linkdialog_test.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. // Copyright 2010 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.ui.editor.LinkDialogTest');
  15. goog.setTestOnly('goog.ui.editor.LinkDialogTest');
  16. goog.require('goog.dom');
  17. goog.require('goog.dom.DomHelper');
  18. goog.require('goog.dom.TagName');
  19. goog.require('goog.editor.BrowserFeature');
  20. goog.require('goog.editor.Link');
  21. goog.require('goog.events');
  22. goog.require('goog.events.EventHandler');
  23. goog.require('goog.events.EventType');
  24. goog.require('goog.events.KeyCodes');
  25. goog.require('goog.style');
  26. goog.require('goog.testing.MockControl');
  27. goog.require('goog.testing.PropertyReplacer');
  28. goog.require('goog.testing.dom');
  29. goog.require('goog.testing.events');
  30. goog.require('goog.testing.events.Event');
  31. goog.require('goog.testing.jsunit');
  32. goog.require('goog.testing.mockmatchers');
  33. goog.require('goog.testing.mockmatchers.ArgumentMatcher');
  34. goog.require('goog.ui.editor.AbstractDialog');
  35. goog.require('goog.ui.editor.LinkDialog');
  36. goog.require('goog.ui.editor.messages');
  37. goog.require('goog.userAgent');
  38. var dialog;
  39. var mockCtrl;
  40. var mockLink;
  41. var mockOkHandler;
  42. var mockGetViewportSize;
  43. var mockWindowOpen;
  44. var isNew;
  45. var anchorElem;
  46. var stubs = new goog.testing.PropertyReplacer();
  47. var ANCHOR_TEXT = 'anchor text';
  48. var ANCHOR_URL = 'http://www.google.com/';
  49. var ANCHOR_EMAIL = 'm@r.cos';
  50. var ANCHOR_MAILTO = 'mailto:' + ANCHOR_EMAIL;
  51. function setUp() {
  52. anchorElem = goog.dom.createElement(goog.dom.TagName.A);
  53. goog.dom.appendChild(goog.dom.getDocument().body, anchorElem);
  54. mockCtrl = new goog.testing.MockControl();
  55. mockLink = mockCtrl.createLooseMock(goog.editor.Link);
  56. mockOkHandler = mockCtrl.createLooseMock(goog.events.EventHandler);
  57. isNew = false;
  58. mockLink.isNew();
  59. mockLink.$anyTimes();
  60. mockLink.$does(function() { return isNew; });
  61. mockLink.getCurrentText();
  62. mockLink.$anyTimes();
  63. mockLink.$does(function() { return anchorElem.innerHTML; });
  64. mockLink.setTextAndUrl(
  65. goog.testing.mockmatchers.isString, goog.testing.mockmatchers.isString);
  66. mockLink.$anyTimes();
  67. mockLink.$does(function(text, url) {
  68. anchorElem.innerHTML = text;
  69. anchorElem.href = url;
  70. });
  71. mockLink.$registerArgumentListVerifier(
  72. 'placeCursorRightOf', function() { return true; });
  73. mockLink.placeCursorRightOf(goog.testing.mockmatchers.iBoolean);
  74. mockLink.$anyTimes();
  75. mockLink.getAnchor();
  76. mockLink.$anyTimes();
  77. mockLink.$returns(anchorElem);
  78. mockWindowOpen = mockCtrl.createFunctionMock('open');
  79. stubs.set(window, 'open', mockWindowOpen);
  80. }
  81. function tearDown() {
  82. dialog.dispose();
  83. goog.dom.removeNode(anchorElem);
  84. stubs.reset();
  85. }
  86. function setUpAnchor(href, text, opt_isNew, opt_target, opt_rel) {
  87. anchorElem.href = href;
  88. anchorElem.innerHTML = text;
  89. isNew = !!opt_isNew;
  90. if (opt_target) {
  91. anchorElem.target = opt_target;
  92. }
  93. if (opt_rel) {
  94. anchorElem.rel = opt_rel;
  95. }
  96. }
  97. /**
  98. * Creates and shows the dialog to be tested.
  99. * @param {Document=} opt_document Document to render the dialog into.
  100. * Defaults to the main window's document.
  101. * @param {boolean=} opt_openInNewWindow Whether the open in new window
  102. * checkbox should be shown.
  103. * @param {boolean=} opt_noFollow Whether rel=nofollow checkbox should be
  104. * shown.
  105. */
  106. function createAndShow(opt_document, opt_openInNewWindow, opt_noFollow) {
  107. dialog = new goog.ui.editor.LinkDialog(
  108. new goog.dom.DomHelper(opt_document), mockLink);
  109. if (opt_openInNewWindow) {
  110. dialog.showOpenLinkInNewWindow(false);
  111. }
  112. if (opt_noFollow) {
  113. dialog.showRelNoFollow();
  114. }
  115. dialog.addEventListener(
  116. goog.ui.editor.AbstractDialog.EventType.OK, mockOkHandler);
  117. dialog.show();
  118. }
  119. /**
  120. * Sets up the mock event handler to expect an OK event with the given text
  121. * and url.
  122. */
  123. function expectOk(linkText, linkUrl, opt_openInNewWindow, opt_noFollow) {
  124. mockOkHandler.handleEvent(
  125. new goog.testing.mockmatchers.ArgumentMatcher(
  126. function(arg) {
  127. return arg.type == goog.ui.editor.AbstractDialog.EventType.OK &&
  128. arg.linkText == linkText && arg.linkUrl == linkUrl &&
  129. arg.openInNewWindow == !!opt_openInNewWindow &&
  130. arg.noFollow == !!opt_noFollow;
  131. },
  132. '{linkText: ' + linkText + ', linkUrl: ' + linkUrl +
  133. ', openInNewWindow: ' + opt_openInNewWindow + ', noFollow: ' +
  134. opt_noFollow + '}'));
  135. }
  136. /**
  137. * Return true if we should use active element in our tests.
  138. * @return {boolean} .
  139. */
  140. function useActiveElement() {
  141. return goog.editor.BrowserFeature.HAS_ACTIVE_ELEMENT ||
  142. goog.userAgent.WEBKIT && goog.userAgent.isVersionOrHigher(9);
  143. }
  144. /**
  145. * Tests that when you show the dialog for a new link, you can switch
  146. * to the URL view.
  147. * @param {Document=} opt_document Document to render the dialog into.
  148. * Defaults to the main window's document.
  149. */
  150. function testShowNewLinkSwitchToUrl(opt_document) {
  151. mockCtrl.$replayAll();
  152. setUpAnchor('', '', true); // Must be done before creating the dialog.
  153. createAndShow(opt_document);
  154. var webRadio = dialog.dom.getElement(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB)
  155. .firstChild;
  156. var emailRadio =
  157. dialog.dom.getElement(goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_TAB)
  158. .firstChild;
  159. assertTrue('Web Radio Button selected', webRadio.checked);
  160. assertFalse('Email Radio Button selected', emailRadio.checked);
  161. if (useActiveElement()) {
  162. assertEquals(
  163. 'Focus should be on url input', getUrlInput(),
  164. dialog.dom.getActiveElement());
  165. }
  166. emailRadio.click();
  167. assertFalse('Web Radio Button selected', webRadio.checked);
  168. assertTrue('Email Radio Button selected', emailRadio.checked);
  169. if (useActiveElement()) {
  170. assertEquals(
  171. 'Focus should be on url input', getEmailInput(),
  172. dialog.dom.getActiveElement());
  173. }
  174. mockCtrl.$verifyAll();
  175. }
  176. /**
  177. * Tests that when you show the dialog for a new link, the input fields are
  178. * empty, the web tab is selected and focus is in the url input field.
  179. * @param {Document=} opt_document Document to render the dialog into.
  180. * Defaults to the main window's document.
  181. */
  182. function testShowForNewLink(opt_document) {
  183. mockCtrl.$replayAll();
  184. setUpAnchor('', '', true); // Must be done before creating the dialog.
  185. createAndShow(opt_document);
  186. assertEquals(
  187. 'Display text input field should be empty', '', getDisplayInputText());
  188. assertEquals('Url input field should be empty', '', getUrlInputText());
  189. assertEquals(
  190. 'On the web tab should be selected', goog.ui.editor.LinkDialog.Id_.ON_WEB,
  191. dialog.curTabId_);
  192. if (useActiveElement()) {
  193. assertEquals(
  194. 'Focus should be on url input', getUrlInput(),
  195. dialog.dom.getActiveElement());
  196. }
  197. mockCtrl.$verifyAll();
  198. }
  199. /**
  200. * Fakes that the mock field is using an iframe and does the same test as
  201. * testShowForNewLink().
  202. */
  203. function testShowForNewLinkWithDiffAppWindow() {
  204. testShowForNewLink(goog.dom.getElement('appWindowIframe').contentDocument);
  205. }
  206. /**
  207. * Tests that when you show the dialog for a url link, the input fields are
  208. * filled in, the web tab is selected and focus is in the url input field.
  209. */
  210. function testShowForUrlLink() {
  211. mockCtrl.$replayAll();
  212. setUpAnchor(ANCHOR_URL, ANCHOR_TEXT);
  213. createAndShow();
  214. assertEquals(
  215. 'Display text input field should be filled in', ANCHOR_TEXT,
  216. getDisplayInputText());
  217. assertEquals(
  218. 'Url input field should be filled in', ANCHOR_URL, getUrlInputText());
  219. assertEquals(
  220. 'On the web tab should be selected', goog.ui.editor.LinkDialog.Id_.ON_WEB,
  221. dialog.curTabId_);
  222. if (useActiveElement()) {
  223. assertEquals(
  224. 'Focus should be on url input', getUrlInput(),
  225. dialog.dom.getActiveElement());
  226. }
  227. mockCtrl.$verifyAll();
  228. }
  229. /**
  230. * Tests that when you show the dialog for a mailto link, the input fields are
  231. * filled in, the email tab is selected and focus is in the email input field.
  232. */
  233. function testShowForMailtoLink() {
  234. mockCtrl.$replayAll();
  235. setUpAnchor(ANCHOR_MAILTO, ANCHOR_TEXT);
  236. createAndShow();
  237. assertEquals(
  238. 'Display text input field should be filled in', ANCHOR_TEXT,
  239. getDisplayInputText());
  240. assertEquals(
  241. 'Email input field should be filled in',
  242. ANCHOR_EMAIL, // The 'mailto:' is not in the input!
  243. getEmailInputText());
  244. assertEquals(
  245. 'Email tab should be selected',
  246. goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS, dialog.curTabId_);
  247. if (useActiveElement()) {
  248. assertEquals(
  249. 'Focus should be on email input', getEmailInput(),
  250. dialog.dom.getActiveElement());
  251. }
  252. mockCtrl.$verifyAll();
  253. }
  254. /**
  255. * Tests that the display text is autogenerated from the url input in the
  256. * right situations (and not generated when appropriate too).
  257. */
  258. function testAutogeneration() {
  259. mockCtrl.$replayAll();
  260. setUpAnchor('', '', true);
  261. createAndShow();
  262. // Simulate typing a url when everything is empty, should autogen.
  263. setUrlInputText(ANCHOR_URL);
  264. assertEquals(
  265. 'Display text should have been autogenerated', ANCHOR_URL,
  266. getDisplayInputText());
  267. // Simulate typing text when url is set, afterwards should not autogen.
  268. setDisplayInputText(ANCHOR_TEXT);
  269. setUrlInputText(ANCHOR_MAILTO);
  270. assertNotEquals(
  271. 'Display text should not have been autogenerated', ANCHOR_MAILTO,
  272. getDisplayInputText());
  273. assertEquals(
  274. 'Display text should have remained the same', ANCHOR_TEXT,
  275. getDisplayInputText());
  276. // Simulate typing text equal to existing url, afterwards should autogen.
  277. setDisplayInputText(ANCHOR_MAILTO);
  278. setUrlInputText(ANCHOR_URL);
  279. assertEquals(
  280. 'Display text should have been autogenerated', ANCHOR_URL,
  281. getDisplayInputText());
  282. mockCtrl.$verifyAll();
  283. }
  284. /**
  285. * Tests that the display text is not autogenerated from the url input in all
  286. * situations when the autogeneration feature is turned off.
  287. */
  288. function testAutogenerationOff() {
  289. mockCtrl.$replayAll();
  290. setUpAnchor('', '', true);
  291. createAndShow();
  292. // Disable the autogen feature
  293. dialog.setAutogenFeatureEnabled(false);
  294. // Simulate typing a url when everything is empty, should not autogen.
  295. setUrlInputText(ANCHOR_URL);
  296. assertEquals(
  297. 'Display text should not have been autogenerated', '',
  298. getDisplayInputText());
  299. // Simulate typing text when url is set, afterwards should not autogen.
  300. setDisplayInputText(ANCHOR_TEXT);
  301. setUrlInputText(ANCHOR_MAILTO);
  302. assertNotEquals(
  303. 'Display text should not have been autogenerated', ANCHOR_MAILTO,
  304. getDisplayInputText());
  305. assertEquals(
  306. 'Display text should have remained the same', ANCHOR_TEXT,
  307. getDisplayInputText());
  308. // Simulate typing text equal to existing url, afterwards should not
  309. // autogen.
  310. setDisplayInputText(ANCHOR_MAILTO);
  311. setUrlInputText(ANCHOR_URL);
  312. assertEquals(
  313. 'Display text should not have been autogenerated', ANCHOR_MAILTO,
  314. getDisplayInputText());
  315. mockCtrl.$verifyAll();
  316. }
  317. /**
  318. * Tests that clicking OK with the url tab selected dispatches an event with
  319. * the proper link data.
  320. */
  321. function testOkForUrl() {
  322. expectOk(ANCHOR_TEXT, ANCHOR_URL);
  323. mockCtrl.$replayAll();
  324. setUpAnchor('', '', true);
  325. createAndShow();
  326. dialog.tabPane_.setSelectedTabId(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB);
  327. setDisplayInputText(ANCHOR_TEXT);
  328. setUrlInputText(ANCHOR_URL);
  329. goog.testing.events.fireClickSequence(dialog.getOkButtonElement());
  330. mockCtrl.$verifyAll();
  331. }
  332. /**
  333. * Tests that clicking OK with the url tab selected but with an email address
  334. * in the url field dispatches an event with the proper link data.
  335. */
  336. function testOkForUrlWithEmail() {
  337. expectOk(ANCHOR_TEXT, ANCHOR_MAILTO);
  338. mockCtrl.$replayAll();
  339. setUpAnchor('', '', true);
  340. createAndShow();
  341. dialog.tabPane_.setSelectedTabId(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB);
  342. setDisplayInputText(ANCHOR_TEXT);
  343. setUrlInputText(ANCHOR_EMAIL);
  344. goog.testing.events.fireClickSequence(dialog.getOkButtonElement());
  345. mockCtrl.$verifyAll();
  346. }
  347. /**
  348. * Tests that clicking OK with the email tab selected dispatches an event with
  349. * the proper link data.
  350. */
  351. function testOkForEmail() {
  352. expectOk(ANCHOR_TEXT, ANCHOR_MAILTO);
  353. mockCtrl.$replayAll();
  354. setUpAnchor('', '', true);
  355. createAndShow();
  356. dialog.tabPane_.setSelectedTabId(
  357. goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_TAB);
  358. setDisplayInputText(ANCHOR_TEXT);
  359. setEmailInputText(ANCHOR_EMAIL);
  360. goog.testing.events.fireClickSequence(dialog.getOkButtonElement());
  361. mockCtrl.$verifyAll();
  362. }
  363. function testOpenLinkInNewWindowNewLink() {
  364. expectOk(ANCHOR_TEXT, ANCHOR_URL, true);
  365. expectOk(ANCHOR_TEXT, ANCHOR_URL, false);
  366. mockCtrl.$replayAll();
  367. setUpAnchor('', '', true);
  368. createAndShow(undefined, true);
  369. dialog.tabPane_.setSelectedTabId(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB);
  370. setDisplayInputText(ANCHOR_TEXT);
  371. setUrlInputText(ANCHOR_URL);
  372. assertFalse(
  373. '"Open in new window" should start unchecked',
  374. getOpenInNewWindowCheckboxChecked());
  375. setOpenInNewWindowCheckboxChecked(true);
  376. assertTrue(
  377. '"Open in new window" should have gotten checked',
  378. getOpenInNewWindowCheckboxChecked());
  379. goog.testing.events.fireClickSequence(dialog.getOkButtonElement());
  380. // Reopen same dialog
  381. dialog.show();
  382. dialog.tabPane_.setSelectedTabId(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB);
  383. setDisplayInputText(ANCHOR_TEXT);
  384. setUrlInputText(ANCHOR_URL);
  385. assertTrue(
  386. '"Open in new window" should remember it was checked',
  387. getOpenInNewWindowCheckboxChecked());
  388. setOpenInNewWindowCheckboxChecked(false);
  389. assertFalse(
  390. '"Open in new window" should have gotten unchecked',
  391. getOpenInNewWindowCheckboxChecked());
  392. goog.testing.events.fireClickSequence(dialog.getOkButtonElement());
  393. }
  394. function testOpenLinkInNewWindowExistingLink() {
  395. mockCtrl.$replayAll();
  396. // Edit an existing link that already opens in a new window.
  397. setUpAnchor('', '', false, '_blank');
  398. createAndShow(undefined, true);
  399. dialog.tabPane_.setSelectedTabId(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB);
  400. setDisplayInputText(ANCHOR_TEXT);
  401. setUrlInputText(ANCHOR_URL);
  402. assertTrue(
  403. '"Open in new window" should start checked for existing link',
  404. getOpenInNewWindowCheckboxChecked());
  405. mockCtrl.$verifyAll();
  406. }
  407. function testRelNoFollowNewLink() {
  408. expectOk(ANCHOR_TEXT, ANCHOR_URL, null, true);
  409. expectOk(ANCHOR_TEXT, ANCHOR_URL, null, false);
  410. mockCtrl.$replayAll();
  411. setUpAnchor('', '', true, true);
  412. createAndShow(null, null, true);
  413. dialog.tabPane_.setSelectedTabId(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB);
  414. setDisplayInputText(ANCHOR_TEXT);
  415. setUrlInputText(ANCHOR_URL);
  416. assertFalse(
  417. 'rel=nofollow should start unchecked',
  418. dialog.relNoFollowCheckbox_.checked);
  419. // Check rel=nofollow and close the dialog.
  420. dialog.relNoFollowCheckbox_.checked = true;
  421. goog.testing.events.fireClickSequence(dialog.getOkButtonElement());
  422. // Reopen the same dialog.
  423. anchorElem.rel = 'foo nofollow bar';
  424. dialog.show();
  425. dialog.tabPane_.setSelectedTabId(goog.ui.editor.LinkDialog.Id_.ON_WEB_TAB);
  426. setDisplayInputText(ANCHOR_TEXT);
  427. setUrlInputText(ANCHOR_URL);
  428. assertTrue(
  429. 'rel=nofollow should start checked when reopening the dialog',
  430. dialog.relNoFollowCheckbox_.checked);
  431. }
  432. function testRelNoFollowExistingLink() {
  433. mockCtrl.$replayAll();
  434. setUpAnchor('', '', null, null, 'foo nofollow bar');
  435. createAndShow(null, null, true);
  436. assertTrue(
  437. 'rel=nofollow should start checked for existing link',
  438. dialog.relNoFollowCheckbox_.checked);
  439. mockCtrl.$verifyAll();
  440. }
  441. /**
  442. * Test that clicking on the test button opens a new window with the correct
  443. * options.
  444. */
  445. function testWebTestButton() {
  446. if (goog.userAgent.GECKO) {
  447. // TODO(robbyw): Figure out why this is flaky and fix it.
  448. return;
  449. }
  450. var width, height;
  451. mockWindowOpen(
  452. ANCHOR_URL, '_blank',
  453. new goog.testing.mockmatchers.ArgumentMatcher(function(str) {
  454. return str ==
  455. 'width=' + width + ',height=' + height +
  456. ',toolbar=1,scrollbars=1,location=1,statusbar=0,' +
  457. 'menubar=1,resizable=1';
  458. }, '3rd arg: (string) window.open() options'));
  459. mockCtrl.$replayAll();
  460. setUpAnchor(ANCHOR_URL, ANCHOR_TEXT);
  461. createAndShow();
  462. // Measure viewport after opening dialog because that might cause scrollbars
  463. // to appear and reduce the viewport size.
  464. var size = goog.dom.getViewportSize(window);
  465. width = Math.max(size.width - 50, 50);
  466. height = Math.max(size.height - 50, 50);
  467. var testLink = goog.testing.dom.findTextNode(
  468. goog.ui.editor.messages.MSG_TEST_THIS_LINK,
  469. dialog.dialogInternal_.getElement());
  470. goog.testing.events.fireClickSequence(testLink.parentNode);
  471. mockCtrl.$verifyAll();
  472. }
  473. /**
  474. * Test that clicking on the test button does not open a new window when
  475. * the event is canceled.
  476. */
  477. function testWebTestButtonPreventDefault() {
  478. mockCtrl.$replayAll();
  479. setUpAnchor(ANCHOR_URL, ANCHOR_TEXT);
  480. createAndShow();
  481. goog.events.listen(
  482. dialog, goog.ui.editor.LinkDialog.EventType.BEFORE_TEST_LINK,
  483. function(e) {
  484. assertEquals(e.url, ANCHOR_URL);
  485. e.preventDefault();
  486. });
  487. var testLink = goog.testing.dom.findTextNode(
  488. goog.ui.editor.messages.MSG_TEST_THIS_LINK,
  489. dialog.dialogInternal_.getElement());
  490. goog.testing.events.fireClickSequence(testLink.parentNode);
  491. mockCtrl.$verifyAll();
  492. }
  493. /**
  494. * Test that the setTextToDisplayVisible() correctly works.
  495. * options.
  496. */
  497. function testSetTextToDisplayVisible() {
  498. mockCtrl.$replayAll();
  499. setUpAnchor('', '', true);
  500. createAndShow();
  501. assertNotEquals(
  502. 'none', goog.style.getStyle(dialog.textToDisplayDiv_, 'display'));
  503. dialog.setTextToDisplayVisible(false);
  504. assertEquals(
  505. 'none', goog.style.getStyle(dialog.textToDisplayDiv_, 'display'));
  506. dialog.setTextToDisplayVisible(true);
  507. assertNotEquals(
  508. 'none', goog.style.getStyle(dialog.textToDisplayDiv_, 'display'));
  509. mockCtrl.$verifyAll();
  510. }
  511. function getDisplayInput() {
  512. return dialog.dom.getElement(goog.ui.editor.LinkDialog.Id_.TEXT_TO_DISPLAY);
  513. }
  514. function getDisplayInputText() {
  515. return getDisplayInput().value;
  516. }
  517. function setDisplayInputText(text) {
  518. var textInput = getDisplayInput();
  519. textInput.value = text;
  520. // Fire event so that dialog behaves like when user types.
  521. fireInputEvent(textInput, goog.events.KeyCodes.M);
  522. }
  523. function getUrlInput() {
  524. var elt = dialog.dom.getElement(goog.ui.editor.LinkDialog.Id_.ON_WEB_INPUT);
  525. assertNotNullNorUndefined('UrlInput must be found', elt);
  526. return elt;
  527. }
  528. function getUrlInputText() {
  529. return getUrlInput().value;
  530. }
  531. function setUrlInputText(text) {
  532. var urlInput = getUrlInput();
  533. urlInput.value = text;
  534. // Fire event so that dialog behaves like when user types.
  535. fireInputEvent(dialog.urlInputHandler_, goog.events.KeyCodes.M);
  536. }
  537. function getEmailInput() {
  538. var elt =
  539. dialog.dom.getElement(goog.ui.editor.LinkDialog.Id_.EMAIL_ADDRESS_INPUT);
  540. assertNotNullNorUndefined('EmailInput must be found', elt);
  541. return elt;
  542. }
  543. function getEmailInputText() {
  544. return getEmailInput().value;
  545. }
  546. function setEmailInputText(text) {
  547. var emailInput = getEmailInput();
  548. emailInput.value = text;
  549. // Fire event so that dialog behaves like when user types.
  550. fireInputEvent(dialog.emailInputHandler_, goog.events.KeyCodes.M);
  551. }
  552. function getOpenInNewWindowCheckboxChecked() {
  553. return dialog.openInNewWindowCheckbox_.checked;
  554. }
  555. function setOpenInNewWindowCheckboxChecked(checked) {
  556. dialog.openInNewWindowCheckbox_.checked = checked;
  557. }
  558. function fireInputEvent(input, keyCode) {
  559. var inputEvent =
  560. new goog.testing.events.Event(goog.events.EventType.INPUT, input);
  561. inputEvent.keyCode = keyCode;
  562. inputEvent.charCode = keyCode;
  563. goog.testing.events.fireBrowserEvent(inputEvent);
  564. }