browser_tip_richSuggestion.js (6275B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Tests that TIP type should be isRichSuggestion. 5 6 "use strict"; 7 8 add_task(async function autosettings() { 9 let result = new UrlbarResult({ 10 type: UrlbarUtils.RESULT_TYPE.TIP, 11 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 12 payload: { 13 type: "test", 14 titleL10n: { id: "urlbar-search-tips-confirm" }, 15 }, 16 }); 17 18 info("Check the following properties are set automatically if TIP result"); 19 Assert.ok(result.isRichSuggestion); 20 Assert.equal(result.richSuggestionIconSize, 24); 21 }); 22 23 add_task(async function ui() { 24 let result = new UrlbarResult({ 25 type: UrlbarUtils.RESULT_TYPE.TIP, 26 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 27 payload: { 28 type: "test", 29 icon: "chrome://global/skin/icons/search-glass.svg", 30 titleL10n: { id: "urlbar-search-tips-confirm" }, 31 descriptionL10n: { id: "urlbar-dismissal-acknowledgment-weather" }, 32 buttons: [ 33 { 34 url: "https://example.com/tab", 35 l10n: { id: "urlbar-search-mode-tabs" }, 36 }, 37 { 38 url: "https://example.com/bookmarks", 39 l10n: { id: "urlbar-search-mode-bookmarks" }, 40 }, 41 ], 42 helpUrl: "https://example.com/help", 43 helpL10n: { 44 id: "urlbar-result-menu-tip-get-help", 45 }, 46 }, 47 }); 48 49 let provider = new UrlbarTestUtils.TestProvider({ 50 results: [result], 51 priority: 1, 52 }); 53 UrlbarProvidersManager.registerProvider(provider); 54 55 await UrlbarTestUtils.promiseAutocompleteResultPopup({ 56 value: "test", 57 window, 58 fireInputEvent: true, 59 }); 60 61 info("Check the container"); 62 let row = await UrlbarTestUtils.waitForAutocompleteResultAt(window, 0); 63 Assert.ok(row.hasAttribute("rich-suggestion")); 64 65 info("Check the icon"); 66 let icon = row.querySelector(".urlbarView-favicon"); 67 Assert.equal(icon.src, "chrome://global/skin/icons/search-glass.svg"); 68 Assert.ok(BrowserTestUtils.isVisible(icon)); 69 70 info("Check the title"); 71 let title = row.querySelector(".urlbarView-title"); 72 Assert.equal(title.dataset.l10nId, "urlbar-search-tips-confirm"); 73 Assert.ok(BrowserTestUtils.isVisible(title)); 74 75 info("Check the description"); 76 let description = row.querySelector(".urlbarView-row-body-description"); 77 Assert.equal( 78 description.dataset.l10nId, 79 "urlbar-dismissal-acknowledgment-weather" 80 ); 81 Assert.ok(BrowserTestUtils.isVisible(description)); 82 83 info("Check the first button"); 84 let firstButton = row.querySelector(".urlbarView-button-0"); 85 Assert.equal(firstButton.dataset.l10nId, "urlbar-search-mode-tabs"); 86 Assert.equal(firstButton.dataset.url, "https://example.com/tab"); 87 Assert.ok(BrowserTestUtils.isVisible(firstButton)); 88 89 info("Check the second button"); 90 let secondButton = row.querySelector(".urlbarView-button-1"); 91 Assert.equal(secondButton.dataset.l10nId, "urlbar-search-mode-bookmarks"); 92 Assert.equal(secondButton.dataset.url, "https://example.com/bookmarks"); 93 Assert.ok(BrowserTestUtils.isVisible(secondButton)); 94 95 info("Check the help"); 96 let help = await UrlbarTestUtils.openResultMenuAndGetItem({ 97 window, 98 command: "help", 99 resultIndex: 0, 100 openByMouse: true, 101 }); 102 Assert.ok(help); 103 Assert.deepEqual(document.l10n.getAttributes(help), { 104 id: "urlbar-result-menu-tip-get-help", 105 args: null, 106 }); 107 gURLBar.view.resultMenu.hidePopup(true); 108 109 info("Check the hidden components"); 110 let url = row.querySelector(".urlbarView-url"); 111 Assert.ok(url); 112 Assert.ok(BrowserTestUtils.isHidden(url)); 113 let titleSeparator = row.querySelector(".urlbarView-title-separator"); 114 Assert.ok(titleSeparator); 115 Assert.ok(BrowserTestUtils.isHidden(titleSeparator)); 116 let action = row.querySelector(".urlbarView-action"); 117 Assert.ok(action); 118 Assert.ok(BrowserTestUtils.isHidden(action)); 119 120 await UrlbarTestUtils.promisePopupClose(window); 121 UrlbarProvidersManager.unregisterProvider(provider); 122 }); 123 124 add_task(async function learn_more() { 125 for (let topic of ["learn_more_topic_1", "learn_more_topic_2", undefined]) { 126 info(`Setup learn more link for ${topic} topic`); 127 let provider = new UrlbarTestUtils.TestProvider({ 128 results: [ 129 new UrlbarResult({ 130 type: UrlbarUtils.RESULT_TYPE.TIP, 131 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 132 payload: { 133 type: "test", 134 titleL10n: { id: "urlbar-search-tips-confirm" }, 135 descriptionL10n: { 136 id: "firefox-suggest-onboarding-main-accept-option-label", 137 parseMarkup: true, 138 }, 139 descriptionLearnMoreTopic: topic, 140 }, 141 }), 142 ], 143 priority: 1, 144 }); 145 UrlbarProvidersManager.registerProvider(provider); 146 147 info("Open urlbar view and find learn more link from 1st row"); 148 await UrlbarTestUtils.promiseAutocompleteResultPopup({ 149 value: "any", 150 window, 151 fireInputEvent: true, 152 }); 153 let row = await UrlbarTestUtils.waitForAutocompleteResultAt(window, 0); 154 let learnMoreLink = row.querySelector( 155 ".urlbarView-row-body-description > a" 156 ); 157 Assert.ok( 158 learnMoreLink, 159 "The descriptionL10n contains a learn-more link, so the element should have a learn-more link" 160 ); 161 162 if (topic) { 163 info("Activate learn more link and check"); 164 let expectedURL = `http://127.0.0.1:8888/support-dummy/${topic}`; 165 let newTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, expectedURL); 166 167 EventUtils.synthesizeKey("KEY_Tab"); 168 Assert.equal( 169 UrlbarTestUtils.getSelectedElement(window), 170 learnMoreLink, 171 "The learn-more link should be selected after pressing Tab" 172 ); 173 Assert.equal( 174 gURLBar.value, 175 expectedURL, 176 "The input value should be the learn-more link URL" 177 ); 178 179 EventUtils.synthesizeKey("KEY_Enter"); 180 info("Wait until expected url is loaded in the current tab"); 181 let newTab = await newTabOpened; 182 Assert.ok(true, "Expected page is loaded"); 183 184 await BrowserTestUtils.removeTab(newTab); 185 await PlacesUtils.history.clear(); 186 } 187 188 await UrlbarTestUtils.promisePopupClose(window); 189 UrlbarProvidersManager.unregisterProvider(provider); 190 } 191 });