toolkit/mozapps/extensions/test/browser/browser_bug562797.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 /**
michael@0 6 * Tests that history navigation works for the add-ons manager.
michael@0 7 */
michael@0 8
michael@0 9 const MAIN_URL = "https://example.com/" + RELATIVE_DIR + "discovery.html";
michael@0 10 const SECOND_URL = "https://example.com/" + RELATIVE_DIR + "releaseNotes.xhtml";
michael@0 11
michael@0 12 var gLoadCompleteCallback = null;
michael@0 13
michael@0 14 var gProgressListener = {
michael@0 15 onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
michael@0 16 // Only care about the network stop status events
michael@0 17 if (!(aStateFlags & (Ci.nsIWebProgressListener.STATE_IS_NETWORK)) ||
michael@0 18 !(aStateFlags & (Ci.nsIWebProgressListener.STATE_STOP)))
michael@0 19 return;
michael@0 20
michael@0 21 if (gLoadCompleteCallback)
michael@0 22 executeSoon(gLoadCompleteCallback);
michael@0 23 gLoadCompleteCallback = null;
michael@0 24 },
michael@0 25
michael@0 26 onLocationChange: function() { },
michael@0 27 onSecurityChange: function() { },
michael@0 28 onProgressChange: function() { },
michael@0 29 onStatusChange: function() { },
michael@0 30
michael@0 31 QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
michael@0 32 Ci.nsISupportsWeakReference]),
michael@0 33 };
michael@0 34
michael@0 35 function waitForLoad(aManager, aCallback) {
michael@0 36 var browser = aManager.document.getElementById("discover-browser");
michael@0 37 browser.addProgressListener(gProgressListener);
michael@0 38
michael@0 39 gLoadCompleteCallback = function() {
michael@0 40 browser.removeProgressListener(gProgressListener);
michael@0 41 aCallback();
michael@0 42 };
michael@0 43 }
michael@0 44
michael@0 45 function clickLink(aManager, aId, aCallback) {
michael@0 46 waitForLoad(aManager, aCallback);
michael@0 47
michael@0 48 var browser = aManager.document.getElementById("discover-browser");
michael@0 49
michael@0 50 var link = browser.contentDocument.getElementById(aId);
michael@0 51 EventUtils.sendMouseEvent({type: "click"}, link);
michael@0 52 }
michael@0 53
michael@0 54 function test() {
michael@0 55 requestLongerTimeout(2);
michael@0 56
michael@0 57 waitForExplicitFinish();
michael@0 58
michael@0 59 Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL);
michael@0 60
michael@0 61 var gProvider = new MockProvider();
michael@0 62 gProvider.createAddons([{
michael@0 63 id: "test1@tests.mozilla.org",
michael@0 64 name: "Test add-on 1",
michael@0 65 description: "foo"
michael@0 66 },
michael@0 67 {
michael@0 68 id: "test2@tests.mozilla.org",
michael@0 69 name: "Test add-on 2",
michael@0 70 description: "bar"
michael@0 71 },
michael@0 72 {
michael@0 73 id: "test3@tests.mozilla.org",
michael@0 74 name: "Test add-on 3",
michael@0 75 type: "theme",
michael@0 76 description: "bar"
michael@0 77 }]);
michael@0 78
michael@0 79 run_next_test();
michael@0 80 }
michael@0 81
michael@0 82 function end_test() {
michael@0 83 finish();
michael@0 84 }
michael@0 85
michael@0 86 function go_back(aManager) {
michael@0 87 if (gUseInContentUI) {
michael@0 88 gBrowser.goBack();
michael@0 89 } else {
michael@0 90 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("back-btn"),
michael@0 91 { }, aManager);
michael@0 92 }
michael@0 93 }
michael@0 94
michael@0 95 function go_back_backspace(aManager) {
michael@0 96 EventUtils.synthesizeKey("VK_BACK_SPACE",{});
michael@0 97 }
michael@0 98
michael@0 99 function go_forward_backspace(aManager) {
michael@0 100 EventUtils.synthesizeKey("VK_BACK_SPACE",{shiftKey: true});
michael@0 101 }
michael@0 102
michael@0 103 function go_forward(aManager) {
michael@0 104 if (gUseInContentUI) {
michael@0 105 gBrowser.goForward();
michael@0 106 } else {
michael@0 107 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("forward-btn"),
michael@0 108 { }, aManager);
michael@0 109 }
michael@0 110 }
michael@0 111
michael@0 112 function check_state(aManager, canGoBack, canGoForward) {
michael@0 113 var doc = aManager.document;
michael@0 114
michael@0 115 if (gUseInContentUI) {
michael@0 116 is(gBrowser.canGoBack, canGoBack, "canGoBack should be correct");
michael@0 117 is(gBrowser.canGoForward, canGoForward, "canGoForward should be correct");
michael@0 118 }
michael@0 119
michael@0 120 if (!is_hidden(doc.getElementById("back-btn"))) {
michael@0 121 is(!doc.getElementById("back-btn").disabled, canGoBack, "Back button should have the right state");
michael@0 122 is(!doc.getElementById("forward-btn").disabled, canGoForward, "Forward button should have the right state");
michael@0 123 }
michael@0 124 }
michael@0 125
michael@0 126 function is_in_list(aManager, view, canGoBack, canGoForward) {
michael@0 127 var doc = aManager.document;
michael@0 128
michael@0 129 is(doc.getElementById("categories").selectedItem.value, view, "Should be on the right category");
michael@0 130 is(doc.getElementById("view-port").selectedPanel.id, "list-view", "Should be on the right view");
michael@0 131
michael@0 132 check_state(aManager, canGoBack, canGoForward);
michael@0 133 }
michael@0 134
michael@0 135 function is_in_search(aManager, query, canGoBack, canGoForward) {
michael@0 136 var doc = aManager.document;
michael@0 137
michael@0 138 is(doc.getElementById("categories").selectedItem.value, "addons://search/", "Should be on the right category");
michael@0 139 is(doc.getElementById("view-port").selectedPanel.id, "search-view", "Should be on the right view");
michael@0 140 is(doc.getElementById("header-search").value, query, "Should have used the right query");
michael@0 141
michael@0 142 check_state(aManager, canGoBack, canGoForward);
michael@0 143 }
michael@0 144
michael@0 145 function is_in_detail(aManager, view, canGoBack, canGoForward) {
michael@0 146 var doc = aManager.document;
michael@0 147
michael@0 148 is(doc.getElementById("categories").selectedItem.value, view, "Should be on the right category");
michael@0 149 is(doc.getElementById("view-port").selectedPanel.id, "detail-view", "Should be on the right view");
michael@0 150
michael@0 151 check_state(aManager, canGoBack, canGoForward);
michael@0 152 }
michael@0 153
michael@0 154 function is_in_discovery(aManager, url, canGoBack, canGoForward) {
michael@0 155 var browser = aManager.document.getElementById("discover-browser");
michael@0 156
michael@0 157 is(aManager.document.getElementById("discover-view").selectedPanel, browser,
michael@0 158 "Browser should be visible");
michael@0 159
michael@0 160 var spec = browser.currentURI.spec;
michael@0 161 var pos = spec.indexOf("#");
michael@0 162 if (pos != -1)
michael@0 163 spec = spec.substring(0, pos);
michael@0 164
michael@0 165 is(spec, url, "Should have loaded the right url");
michael@0 166
michael@0 167 check_state(aManager, canGoBack, canGoForward);
michael@0 168 }
michael@0 169
michael@0 170 function double_click_addon_element(aManager, aId) {
michael@0 171 var addon = get_addon_element(aManager, aId);
michael@0 172 addon.parentNode.ensureElementIsVisible(addon);
michael@0 173 EventUtils.synthesizeMouseAtCenter(addon, { clickCount: 1 }, aManager);
michael@0 174 EventUtils.synthesizeMouseAtCenter(addon, { clickCount: 2 }, aManager);
michael@0 175 }
michael@0 176
michael@0 177 // Tests simple forward and back navigation and that the right heading and
michael@0 178 // category is selected
michael@0 179 add_test(function() {
michael@0 180 open_manager("addons://list/extension", function(aManager) {
michael@0 181 info("Part 1");
michael@0 182 is_in_list(aManager, "addons://list/extension", false, false);
michael@0 183
michael@0 184 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-plugin"), { }, aManager);
michael@0 185
michael@0 186 wait_for_view_load(aManager, function(aManager) {
michael@0 187 info("Part 2");
michael@0 188 is_in_list(aManager, "addons://list/plugin", true, false);
michael@0 189
michael@0 190 go_back(aManager);
michael@0 191
michael@0 192 wait_for_view_load(aManager, function(aManager) {
michael@0 193 info("Part 3");
michael@0 194 is_in_list(aManager, "addons://list/extension", false, true);
michael@0 195
michael@0 196 go_forward(aManager);
michael@0 197
michael@0 198 wait_for_view_load(aManager, function(aManager) {
michael@0 199 info("Part 4");
michael@0 200 is_in_list(aManager, "addons://list/plugin", true, false);
michael@0 201
michael@0 202 go_back(aManager);
michael@0 203
michael@0 204 wait_for_view_load(aManager, function(aManager) {
michael@0 205 info("Part 5");
michael@0 206 is_in_list(aManager, "addons://list/extension", false, true);
michael@0 207
michael@0 208 double_click_addon_element(aManager, "test1@tests.mozilla.org");
michael@0 209
michael@0 210 wait_for_view_load(aManager, function(aManager) {
michael@0 211 info("Part 6");
michael@0 212 is_in_detail(aManager, "addons://list/extension", true, false);
michael@0 213
michael@0 214 go_back(aManager);
michael@0 215
michael@0 216 wait_for_view_load(aManager, function(aManager) {
michael@0 217 info("Part 7");
michael@0 218 is_in_list(aManager, "addons://list/extension", false, true);
michael@0 219
michael@0 220 close_manager(aManager, run_next_test);
michael@0 221 });
michael@0 222 });
michael@0 223 });
michael@0 224 });
michael@0 225 });
michael@0 226 });
michael@0 227 });
michael@0 228 });
michael@0 229
michael@0 230 // Tests that browsing to the add-ons manager from a website and going back works
michael@0 231 // Only relevant for in-content UI
michael@0 232 add_test(function() {
michael@0 233 if (!gUseInContentUI) {
michael@0 234 run_next_test();
michael@0 235 return;
michael@0 236 }
michael@0 237
michael@0 238 info("Part 1");
michael@0 239 gBrowser.selectedTab = gBrowser.addTab();
michael@0 240 gBrowser.loadURI("http://example.com/");
michael@0 241 gBrowser.addEventListener("pageshow", function(event) {
michael@0 242 if (event.target.location != "http://example.com/")
michael@0 243 return;
michael@0 244 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 245
michael@0 246 //Must let the load complete for it to go into the session history
michael@0 247 executeSoon(function() {
michael@0 248 info("Part 2");
michael@0 249 ok(!gBrowser.canGoBack, "Should not be able to go back");
michael@0 250 ok(!gBrowser.canGoForward, "Should not be able to go forward");
michael@0 251
michael@0 252 gBrowser.loadURI("about:addons");
michael@0 253 gBrowser.addEventListener("pageshow", function(event) {
michael@0 254 if (event.target.location != "about:addons")
michael@0 255 return;
michael@0 256 gBrowser.removeEventListener("pageshow", arguments.callee, true);
michael@0 257
michael@0 258 wait_for_view_load(gBrowser.contentWindow.wrappedJSObject, function(aManager) {
michael@0 259 info("Part 3");
michael@0 260 is_in_list(aManager, "addons://list/extension", true, false);
michael@0 261
michael@0 262 go_back(aManager);
michael@0 263 gBrowser.addEventListener("pageshow", function() {
michael@0 264 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 265 info("Part 4");
michael@0 266 is(gBrowser.currentURI.spec, "http://example.com/", "Should be showing the webpage");
michael@0 267 ok(!gBrowser.canGoBack, "Should not be able to go back");
michael@0 268 ok(gBrowser.canGoForward, "Should be able to go forward");
michael@0 269
michael@0 270 go_forward(aManager);
michael@0 271 gBrowser.addEventListener("pageshow", function() {
michael@0 272 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 273 wait_for_view_load(gBrowser.contentWindow.wrappedJSObject, function(aManager) {
michael@0 274 info("Part 5");
michael@0 275 is_in_list(aManager, "addons://list/extension", true, false);
michael@0 276
michael@0 277 close_manager(aManager, run_next_test);
michael@0 278 });
michael@0 279 }, false);
michael@0 280 }, false);
michael@0 281 });
michael@0 282 }, true);
michael@0 283 });
michael@0 284 }, false);
michael@0 285 });
michael@0 286
michael@0 287 // Tests simple forward and back navigation and that the right heading and
michael@0 288 // category is selected -- Keyboard navigation [Bug 565359]
michael@0 289 // Only add the test if the backspace key navigates back and addon-manager
michael@0 290 // loaded in a tab
michael@0 291 add_test(function() {
michael@0 292
michael@0 293 if (!gUseInContentUI || (Services.prefs.getIntPref("browser.backspace_action") != 0)) {
michael@0 294 run_next_test();
michael@0 295 return;
michael@0 296 }
michael@0 297
michael@0 298 open_manager("addons://list/extension", function(aManager) {
michael@0 299 info("Part 1");
michael@0 300 is_in_list(aManager, "addons://list/extension", false, false);
michael@0 301
michael@0 302 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-plugin"), { }, aManager);
michael@0 303
michael@0 304 wait_for_view_load(aManager, function(aManager) {
michael@0 305 info("Part 2");
michael@0 306 is_in_list(aManager, "addons://list/plugin", true, false);
michael@0 307
michael@0 308 go_back_backspace(aManager);
michael@0 309
michael@0 310 wait_for_view_load(aManager, function(aManager) {
michael@0 311 info("Part 3");
michael@0 312 is_in_list(aManager, "addons://list/extension", false, true);
michael@0 313
michael@0 314 go_forward_backspace(aManager);
michael@0 315
michael@0 316 wait_for_view_load(aManager, function(aManager) {
michael@0 317 info("Part 4");
michael@0 318 is_in_list(aManager, "addons://list/plugin", true, false);
michael@0 319
michael@0 320 go_back_backspace(aManager);
michael@0 321
michael@0 322 wait_for_view_load(aManager, function(aManager) {
michael@0 323 info("Part 5");
michael@0 324 is_in_list(aManager, "addons://list/extension", false, true);
michael@0 325
michael@0 326 double_click_addon_element(aManager, "test1@tests.mozilla.org");
michael@0 327
michael@0 328 wait_for_view_load(aManager, function(aManager) {
michael@0 329 info("Part 6");
michael@0 330 is_in_detail(aManager, "addons://list/extension", true, false);
michael@0 331
michael@0 332 go_back_backspace(aManager);
michael@0 333
michael@0 334 wait_for_view_load(aManager, function(aManager) {
michael@0 335 info("Part 7");
michael@0 336 is_in_list(aManager, "addons://list/extension", false, true);
michael@0 337
michael@0 338 close_manager(aManager, run_next_test);
michael@0 339 });
michael@0 340 });
michael@0 341 });
michael@0 342 });
michael@0 343 });
michael@0 344 });
michael@0 345 });
michael@0 346 });
michael@0 347
michael@0 348
michael@0 349 // Tests that opening a custom first view only stores a single history entry
michael@0 350 add_test(function() {
michael@0 351 open_manager("addons://list/plugin", function(aManager) {
michael@0 352 info("Part 1");
michael@0 353 is_in_list(aManager, "addons://list/plugin", false, false);
michael@0 354
michael@0 355 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-extension"), { }, aManager);
michael@0 356
michael@0 357 wait_for_view_load(aManager, function(aManager) {
michael@0 358 info("Part 2");
michael@0 359 is_in_list(aManager, "addons://list/extension", true, false);
michael@0 360
michael@0 361 go_back(aManager);
michael@0 362
michael@0 363 wait_for_view_load(aManager, function(aManager) {
michael@0 364 info("Part 3");
michael@0 365 is_in_list(aManager, "addons://list/plugin", false, true);
michael@0 366
michael@0 367 close_manager(aManager, run_next_test);
michael@0 368 });
michael@0 369 });
michael@0 370 });
michael@0 371 });
michael@0 372
michael@0 373
michael@0 374 // Tests that opening a view while the manager is already open adds a new
michael@0 375 // history entry
michael@0 376 add_test(function() {
michael@0 377 open_manager("addons://list/extension", function(aManager) {
michael@0 378 info("Part 1");
michael@0 379 is_in_list(aManager, "addons://list/extension", false, false);
michael@0 380
michael@0 381 aManager.loadView("addons://list/plugin");
michael@0 382
michael@0 383 wait_for_view_load(aManager, function(aManager) {
michael@0 384 info("Part 2");
michael@0 385 is_in_list(aManager, "addons://list/plugin", true, false);
michael@0 386
michael@0 387 go_back(aManager);
michael@0 388
michael@0 389 wait_for_view_load(aManager, function(aManager) {
michael@0 390 info("Part 3");
michael@0 391 is_in_list(aManager, "addons://list/extension", false, true);
michael@0 392
michael@0 393 go_forward(aManager);
michael@0 394
michael@0 395 wait_for_view_load(aManager, function(aManager) {
michael@0 396 info("Part 4");
michael@0 397 is_in_list(aManager, "addons://list/plugin", true, false);
michael@0 398
michael@0 399 close_manager(aManager, run_next_test);
michael@0 400 });
michael@0 401 });
michael@0 402 });
michael@0 403 });
michael@0 404 });
michael@0 405
michael@0 406 // Tests than navigating to a website and then going back returns to the
michael@0 407 // previous view
michael@0 408 // Only relevant for in-content UI
michael@0 409 add_test(function() {
michael@0 410 if (!gUseInContentUI) {
michael@0 411 run_next_test();
michael@0 412 return;
michael@0 413 }
michael@0 414
michael@0 415 open_manager("addons://list/plugin", function(aManager) {
michael@0 416 info("Part 1");
michael@0 417 is_in_list(aManager, "addons://list/plugin", false, false);
michael@0 418
michael@0 419 gBrowser.loadURI("http://example.com/");
michael@0 420 gBrowser.addEventListener("pageshow", function(event) {
michael@0 421 if (event.target.location != "http://example.com/")
michael@0 422 return;
michael@0 423 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 424 info("Part 2");
michael@0 425
michael@0 426 executeSoon(function() {
michael@0 427 ok(gBrowser.canGoBack, "Should be able to go back");
michael@0 428 ok(!gBrowser.canGoForward, "Should not be able to go forward");
michael@0 429
michael@0 430 go_back(aManager);
michael@0 431
michael@0 432 gBrowser.addEventListener("pageshow", function(event) {
michael@0 433 if (event.target.location != "about:addons")
michael@0 434 return;
michael@0 435 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 436
michael@0 437 wait_for_view_load(gBrowser.contentWindow.wrappedJSObject, function(aManager) {
michael@0 438 info("Part 3");
michael@0 439 is_in_list(aManager, "addons://list/plugin", false, true);
michael@0 440
michael@0 441 go_forward(aManager);
michael@0 442 gBrowser.addEventListener("pageshow", function(event) {
michael@0 443 if (event.target.location != "http://example.com/")
michael@0 444 return;
michael@0 445 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 446 info("Part 4");
michael@0 447
michael@0 448 executeSoon(function() {
michael@0 449 ok(gBrowser.canGoBack, "Should be able to go back");
michael@0 450 ok(!gBrowser.canGoForward, "Should not be able to go forward");
michael@0 451
michael@0 452 go_back(aManager);
michael@0 453
michael@0 454 gBrowser.addEventListener("pageshow", function(event) {
michael@0 455 if (event.target.location != "about:addons")
michael@0 456 return;
michael@0 457 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 458 wait_for_view_load(gBrowser.contentWindow.wrappedJSObject, function(aManager) {
michael@0 459 info("Part 5");
michael@0 460 is_in_list(aManager, "addons://list/plugin", false, true);
michael@0 461
michael@0 462 close_manager(aManager, run_next_test);
michael@0 463 });
michael@0 464 }, false);
michael@0 465 });
michael@0 466 }, false);
michael@0 467 });
michael@0 468 }, false);
michael@0 469 });
michael@0 470 }, false);
michael@0 471 });
michael@0 472 });
michael@0 473
michael@0 474 // Tests that going back to search results works
michael@0 475 add_test(function() {
michael@0 476 // Before we open the add-ons manager, we should make sure that no filter
michael@0 477 // has been set. If one is set, we remove it.
michael@0 478 // This is for the check below, from bug 611459.
michael@0 479 let RDF = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
michael@0 480 let store = RDF.GetDataSource("rdf:local-store");
michael@0 481 let filterResource = RDF.GetResource("about:addons#search-filter-radiogroup");
michael@0 482 let filterProperty = RDF.GetResource("value");
michael@0 483 let filterTarget = store.GetTarget(filterResource, filterProperty, true);
michael@0 484
michael@0 485 if (filterTarget) {
michael@0 486 is(filterTarget instanceof Ci.nsIRDFLiteral, true,
michael@0 487 "Filter should be a value");
michael@0 488 store.Unassert(filterResource, filterProperty, filterTarget);
michael@0 489 }
michael@0 490
michael@0 491 open_manager("addons://list/extension", function(aManager) {
michael@0 492 info("Part 1");
michael@0 493 is_in_list(aManager, "addons://list/extension", false, false);
michael@0 494
michael@0 495 var search = aManager.document.getElementById("header-search");
michael@0 496 search.focus();
michael@0 497 search.value = "bar";
michael@0 498 EventUtils.synthesizeKey("VK_RETURN", {}, aManager);
michael@0 499
michael@0 500 wait_for_view_load(aManager, function(aManager) {
michael@0 501 // Remote search is meant to be checked by default (bug 611459), so we
michael@0 502 // confirm that and then switch to a local search.
michael@0 503 var localFilter = aManager.document.getElementById("search-filter-local");
michael@0 504 var remoteFilter = aManager.document.getElementById("search-filter-remote");
michael@0 505
michael@0 506 is(remoteFilter.selected, true, "Remote filter should be set by default");
michael@0 507
michael@0 508 var list = aManager.document.getElementById("search-list");
michael@0 509 list.ensureElementIsVisible(localFilter);
michael@0 510 EventUtils.synthesizeMouseAtCenter(localFilter, { }, aManager);
michael@0 511
michael@0 512 is(localFilter.selected, true, "Should have changed to local filter");
michael@0 513
michael@0 514 // Now we continue with the normal test.
michael@0 515
michael@0 516 info("Part 2");
michael@0 517 is_in_search(aManager, "bar", true, false);
michael@0 518 check_all_in_list(aManager, ["test2@tests.mozilla.org", "test3@tests.mozilla.org"]);
michael@0 519
michael@0 520 double_click_addon_element(aManager, "test2@tests.mozilla.org");
michael@0 521
michael@0 522 wait_for_view_load(aManager, function(aManager) {
michael@0 523 info("Part 3");
michael@0 524 is_in_detail(aManager, "addons://search/", true, false);
michael@0 525
michael@0 526 go_back(aManager);
michael@0 527 wait_for_view_load(aManager, function(aManager) {
michael@0 528 info("Part 4");
michael@0 529 is_in_search(aManager, "bar", true, true);
michael@0 530 check_all_in_list(aManager, ["test2@tests.mozilla.org", "test3@tests.mozilla.org"]);
michael@0 531
michael@0 532 go_forward(aManager);
michael@0 533 wait_for_view_load(aManager, function(aManager) {
michael@0 534 info("Part 5");
michael@0 535 is_in_detail(aManager, "addons://search/", true, false);
michael@0 536
michael@0 537 close_manager(aManager, run_next_test);
michael@0 538 });
michael@0 539 });
michael@0 540 });
michael@0 541 });
michael@0 542 });
michael@0 543 });
michael@0 544
michael@0 545 // Tests that going back from a webpage to a detail view loaded from a search
michael@0 546 // result works
michael@0 547 // Only relevant for in-content UI
michael@0 548 add_test(function() {
michael@0 549 if (!gUseInContentUI) {
michael@0 550 run_next_test();
michael@0 551 return;
michael@0 552 }
michael@0 553
michael@0 554 open_manager("addons://list/extension", function(aManager) {
michael@0 555 info("Part 1");
michael@0 556 is_in_list(aManager, "addons://list/extension", false, false);
michael@0 557
michael@0 558 var search = aManager.document.getElementById("header-search");
michael@0 559 search.focus();
michael@0 560 search.value = "bar";
michael@0 561 EventUtils.synthesizeKey("VK_RETURN", {});
michael@0 562
michael@0 563 wait_for_view_load(aManager, function(aManager) {
michael@0 564 info("Part 2");
michael@0 565 is_in_search(aManager, "bar", true, false);
michael@0 566 check_all_in_list(aManager, ["test2@tests.mozilla.org", "test3@tests.mozilla.org"]);
michael@0 567
michael@0 568 double_click_addon_element(aManager, "test2@tests.mozilla.org");
michael@0 569
michael@0 570 wait_for_view_load(aManager, function(aManager) {
michael@0 571 info("Part 3");
michael@0 572 is_in_detail(aManager, "addons://search/", true, false);
michael@0 573
michael@0 574 gBrowser.loadURI("http://example.com/");
michael@0 575 gBrowser.addEventListener("pageshow", function(event) {
michael@0 576 if (event.target.location != "http://example.com/")
michael@0 577 return;
michael@0 578 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 579
michael@0 580 info("Part 4");
michael@0 581 executeSoon(function() {
michael@0 582 ok(gBrowser.canGoBack, "Should be able to go back");
michael@0 583 ok(!gBrowser.canGoForward, "Should not be able to go forward");
michael@0 584
michael@0 585 go_back(aManager);
michael@0 586 gBrowser.addEventListener("pageshow", function(event) {
michael@0 587 if (event.target.location != "about:addons")
michael@0 588 return;
michael@0 589 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 590
michael@0 591 wait_for_view_load(gBrowser.contentWindow.wrappedJSObject, function(aManager) {
michael@0 592 info("Part 5");
michael@0 593 is_in_detail(aManager, "addons://search/", true, true);
michael@0 594
michael@0 595 go_back(aManager);
michael@0 596 wait_for_view_load(aManager, function(aManager) {
michael@0 597 info("Part 6");
michael@0 598 is_in_search(aManager, "bar", true, true);
michael@0 599 check_all_in_list(aManager, ["test2@tests.mozilla.org", "test3@tests.mozilla.org"]);
michael@0 600
michael@0 601 close_manager(aManager, run_next_test);
michael@0 602 });
michael@0 603 });
michael@0 604 }, false);
michael@0 605 });
michael@0 606 }, false);
michael@0 607 });
michael@0 608 });
michael@0 609 });
michael@0 610 });
michael@0 611
michael@0 612 // Tests that refreshing a list view does not affect the history
michael@0 613 // Only relevant for in-content UI
michael@0 614 add_test(function() {
michael@0 615 if (!gUseInContentUI) {
michael@0 616 run_next_test();
michael@0 617 return;
michael@0 618 }
michael@0 619
michael@0 620 open_manager("addons://list/extension", function(aManager) {
michael@0 621 info("Part 1");
michael@0 622 is_in_list(aManager, "addons://list/extension", false, false);
michael@0 623
michael@0 624 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-plugin"), { }, aManager);
michael@0 625
michael@0 626 wait_for_view_load(aManager, function(aManager) {
michael@0 627 info("Part 2");
michael@0 628 is_in_list(aManager, "addons://list/plugin", true, false);
michael@0 629
michael@0 630 gBrowser.reload();
michael@0 631 gBrowser.addEventListener("pageshow", function(event) {
michael@0 632 if (event.target.location != "about:addons")
michael@0 633 return;
michael@0 634 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 635
michael@0 636 wait_for_view_load(gBrowser.contentWindow.wrappedJSObject, function(aManager) {
michael@0 637 info("Part 3");
michael@0 638 is_in_list(aManager, "addons://list/plugin", true, false);
michael@0 639
michael@0 640 go_back(aManager);
michael@0 641 wait_for_view_load(aManager, function(aManager) {
michael@0 642 info("Part 4");
michael@0 643 is_in_list(aManager, "addons://list/extension", false, true);
michael@0 644
michael@0 645 close_manager(aManager, run_next_test);
michael@0 646 });
michael@0 647 });
michael@0 648 }, false);
michael@0 649 });
michael@0 650 });
michael@0 651 });
michael@0 652
michael@0 653 // Tests that refreshing a detail view does not affect the history
michael@0 654 // Only relevant for in-content UI
michael@0 655 add_test(function() {
michael@0 656 if (!gUseInContentUI) {
michael@0 657 run_next_test();
michael@0 658 return;
michael@0 659 }
michael@0 660
michael@0 661 open_manager(null, function(aManager) {
michael@0 662 info("Part 1");
michael@0 663 is_in_list(aManager, "addons://list/extension", false, false);
michael@0 664
michael@0 665 double_click_addon_element(aManager, "test1@tests.mozilla.org");
michael@0 666
michael@0 667 wait_for_view_load(aManager, function(aManager) {
michael@0 668 info("Part 2");
michael@0 669 is_in_detail(aManager, "addons://list/extension", true, false);
michael@0 670
michael@0 671 gBrowser.reload();
michael@0 672 gBrowser.addEventListener("pageshow", function(event) {
michael@0 673 if (event.target.location != "about:addons")
michael@0 674 return;
michael@0 675 gBrowser.removeEventListener("pageshow", arguments.callee, false);
michael@0 676
michael@0 677 wait_for_view_load(gBrowser.contentWindow.wrappedJSObject, function(aManager) {
michael@0 678 info("Part 3");
michael@0 679 is_in_detail(aManager, "addons://list/extension", true, false);
michael@0 680
michael@0 681 go_back(aManager);
michael@0 682 wait_for_view_load(aManager, function(aManager) {
michael@0 683 info("Part 4");
michael@0 684 is_in_list(aManager, "addons://list/extension", false, true);
michael@0 685
michael@0 686 close_manager(aManager, run_next_test);
michael@0 687 });
michael@0 688 });
michael@0 689 }, false);
michael@0 690 });
michael@0 691 });
michael@0 692 });
michael@0 693
michael@0 694 // Tests that removing an extension from the detail view goes back and doesn't
michael@0 695 // allow you to go forward again.
michael@0 696 add_test(function() {
michael@0 697 open_manager("addons://list/extension", function(aManager) {
michael@0 698 info("Part 1");
michael@0 699 is_in_list(aManager, "addons://list/extension", false, false);
michael@0 700
michael@0 701 double_click_addon_element(aManager, "test1@tests.mozilla.org");
michael@0 702
michael@0 703 wait_for_view_load(aManager, function(aManager) {
michael@0 704 info("Part 2");
michael@0 705 is_in_detail(aManager, "addons://list/extension", true, false);
michael@0 706
michael@0 707 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("detail-uninstall-btn"),
michael@0 708 { }, aManager);
michael@0 709
michael@0 710 wait_for_view_load(aManager, function() {
michael@0 711 if (gUseInContentUI) {
michael@0 712 // TODO until bug 590661 is fixed the back button will be enabled
michael@0 713 // when displaying in content
michael@0 714 is_in_list(aManager, "addons://list/extension", true, false);
michael@0 715 } else {
michael@0 716 is_in_list(aManager, "addons://list/extension", false, false);
michael@0 717 }
michael@0 718
michael@0 719 close_manager(aManager, run_next_test);
michael@0 720 });
michael@0 721 });
michael@0 722 });
michael@0 723 });
michael@0 724
michael@0 725 // Tests that the back and forward buttons only show up for windowed mode
michael@0 726 add_test(function() {
michael@0 727 open_manager(null, function(aManager) {
michael@0 728 var doc = aManager.document;
michael@0 729
michael@0 730 if (gUseInContentUI) {
michael@0 731 var btn = document.getElementById("back-button");
michael@0 732 if (!btn || is_hidden(btn)) {
michael@0 733 is_element_visible(doc.getElementById("back-btn"), "Back button should not be hidden");
michael@0 734 is_element_visible(doc.getElementById("forward-btn"), "Forward button should not be hidden");
michael@0 735 } else {
michael@0 736 is_element_hidden(doc.getElementById("back-btn"), "Back button should be hidden");
michael@0 737 is_element_hidden(doc.getElementById("forward-btn"), "Forward button should be hidden");
michael@0 738 }
michael@0 739 } else {
michael@0 740 is_element_visible(doc.getElementById("back-btn"), "Back button should not be hidden");
michael@0 741 is_element_visible(doc.getElementById("forward-btn"), "Forward button should not be hidden");
michael@0 742 }
michael@0 743
michael@0 744 close_manager(aManager, run_next_test);
michael@0 745 });
michael@0 746 });
michael@0 747
michael@0 748 // Tests that opening the manager opens the last view
michael@0 749 add_test(function() {
michael@0 750 open_manager("addons://list/plugin", function(aManager) {
michael@0 751 info("Part 1");
michael@0 752 is_in_list(aManager, "addons://list/plugin", false, false);
michael@0 753
michael@0 754 close_manager(aManager, function() {
michael@0 755 open_manager(null, function(aManager) {
michael@0 756 info("Part 2");
michael@0 757 is_in_list(aManager, "addons://list/plugin", false, false);
michael@0 758
michael@0 759 close_manager(aManager, run_next_test);
michael@0 760 });
michael@0 761 });
michael@0 762 });
michael@0 763 });
michael@0 764
michael@0 765 // Tests that navigating the discovery page works when that was the first view
michael@0 766 add_test(function() {
michael@0 767 open_manager("addons://discover/", function(aManager) {
michael@0 768 info("1");
michael@0 769 is_in_discovery(aManager, MAIN_URL, false, false);
michael@0 770
michael@0 771 clickLink(aManager, "link-good", function() {
michael@0 772 info("2");
michael@0 773 is_in_discovery(aManager, SECOND_URL, true, false);
michael@0 774
michael@0 775 waitForLoad(aManager, function() {
michael@0 776 info("3");
michael@0 777 is_in_discovery(aManager, MAIN_URL, false, true);
michael@0 778
michael@0 779 waitForLoad(aManager, function() {
michael@0 780 is_in_discovery(aManager, SECOND_URL, true, false);
michael@0 781
michael@0 782 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-plugin"), { }, aManager);
michael@0 783
michael@0 784 wait_for_view_load(aManager, function(aManager) {
michael@0 785 is_in_list(aManager, "addons://list/plugin", true, false);
michael@0 786
michael@0 787 go_back(aManager);
michael@0 788
michael@0 789 wait_for_view_load(aManager, function(aManager) {
michael@0 790 is_in_discovery(aManager, SECOND_URL, true, true);
michael@0 791
michael@0 792 go_back(aManager);
michael@0 793
michael@0 794 waitForLoad(aManager, function() {
michael@0 795 is_in_discovery(aManager, MAIN_URL, false, true);
michael@0 796
michael@0 797 close_manager(aManager, run_next_test);
michael@0 798 });
michael@0 799 });
michael@0 800 });
michael@0 801 });
michael@0 802
michael@0 803 go_forward(aManager);
michael@0 804 });
michael@0 805
michael@0 806 go_back(aManager);
michael@0 807 });
michael@0 808 });
michael@0 809 });
michael@0 810
michael@0 811 // Tests that navigating the discovery page works when that was the second view
michael@0 812 add_test(function() {
michael@0 813 open_manager("addons://list/plugin", function(aManager) {
michael@0 814 is_in_list(aManager, "addons://list/plugin", false, false);
michael@0 815
michael@0 816 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-discover"), { }, aManager);
michael@0 817
michael@0 818 wait_for_view_load(aManager, function(aManager) {
michael@0 819 is_in_discovery(aManager, MAIN_URL, true, false);
michael@0 820
michael@0 821 clickLink(aManager, "link-good", function() {
michael@0 822 is_in_discovery(aManager, SECOND_URL, true, false);
michael@0 823
michael@0 824 waitForLoad(aManager, function() {
michael@0 825 is_in_discovery(aManager, MAIN_URL, true, true);
michael@0 826
michael@0 827 waitForLoad(aManager, function() {
michael@0 828 is_in_discovery(aManager, SECOND_URL, true, false);
michael@0 829
michael@0 830 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-plugin"), { }, aManager);
michael@0 831
michael@0 832 wait_for_view_load(aManager, function(aManager) {
michael@0 833 is_in_list(aManager, "addons://list/plugin", true, false);
michael@0 834
michael@0 835 go_back(aManager);
michael@0 836
michael@0 837 wait_for_view_load(aManager, function(aManager) {
michael@0 838 is_in_discovery(aManager, SECOND_URL, true, true);
michael@0 839
michael@0 840 go_back(aManager);
michael@0 841
michael@0 842 waitForLoad(aManager, function() {
michael@0 843 is_in_discovery(aManager, MAIN_URL, true, true);
michael@0 844
michael@0 845 go_back(aManager);
michael@0 846
michael@0 847 wait_for_view_load(aManager, function(aManager) {
michael@0 848 is_in_list(aManager, "addons://list/plugin", false, true);
michael@0 849
michael@0 850 go_forward(aManager);
michael@0 851
michael@0 852 wait_for_view_load(aManager, function(aManager) {
michael@0 853 is_in_discovery(aManager, MAIN_URL, true, true);
michael@0 854
michael@0 855 waitForLoad(aManager, function() {
michael@0 856 is_in_discovery(aManager, SECOND_URL, true, true);
michael@0 857
michael@0 858 close_manager(aManager, run_next_test);
michael@0 859 });
michael@0 860
michael@0 861 go_forward(aManager);
michael@0 862 });
michael@0 863 });
michael@0 864 });
michael@0 865 });
michael@0 866 });
michael@0 867 });
michael@0 868
michael@0 869 go_forward(aManager);
michael@0 870 });
michael@0 871
michael@0 872 go_back(aManager);
michael@0 873 });
michael@0 874 });
michael@0 875 });
michael@0 876 });
michael@0 877
michael@0 878 // Tests that when displaying in-content and opened in the background the back
michael@0 879 // and forward buttons still appear when switching tabs
michael@0 880 add_test(function() {
michael@0 881 if (!gUseInContentUI) {
michael@0 882 run_next_test();
michael@0 883 return;
michael@0 884 }
michael@0 885
michael@0 886 var tab = gBrowser.addTab("about:addons");
michael@0 887 var browser = gBrowser.getBrowserForTab(tab);
michael@0 888
michael@0 889 browser.addEventListener("pageshow", function(event) {
michael@0 890 if (event.target.location.href != "about:addons")
michael@0 891 return;
michael@0 892 browser.removeEventListener("pageshow", arguments.callee, true);
michael@0 893
michael@0 894 wait_for_manager_load(browser.contentWindow.wrappedJSObject, function() {
michael@0 895 wait_for_view_load(browser.contentWindow.wrappedJSObject, function(aManager) {
michael@0 896 gBrowser.selectedTab = tab;
michael@0 897
michael@0 898 var doc = aManager.document;
michael@0 899 var btn = document.getElementById("back-button");
michael@0 900 if (!btn || is_hidden(btn)) {
michael@0 901 is_element_visible(doc.getElementById("back-btn"), "Back button should not be hidden");
michael@0 902 is_element_visible(doc.getElementById("forward-btn"), "Forward button should not be hidden");
michael@0 903 } else {
michael@0 904 is_element_hidden(doc.getElementById("back-btn"), "Back button should be hidden");
michael@0 905 is_element_hidden(doc.getElementById("forward-btn"), "Forward button should be hidden");
michael@0 906 }
michael@0 907
michael@0 908 close_manager(aManager, run_next_test);
michael@0 909 });
michael@0 910 });
michael@0 911 }, true);
michael@0 912 });
michael@0 913
michael@0 914 // Tests that refreshing the disicovery pane integrates properly with history
michael@0 915 add_test(function() {
michael@0 916 open_manager("addons://list/plugin", function(aManager) {
michael@0 917 is_in_list(aManager, "addons://list/plugin", false, false);
michael@0 918
michael@0 919 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-discover"), { }, aManager);
michael@0 920
michael@0 921 wait_for_view_load(aManager, function(aManager) {
michael@0 922 is_in_discovery(aManager, MAIN_URL, true, false);
michael@0 923
michael@0 924 clickLink(aManager, "link-good", function() {
michael@0 925 is_in_discovery(aManager, SECOND_URL, true, false);
michael@0 926
michael@0 927 EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-discover"), { }, aManager);
michael@0 928
michael@0 929 waitForLoad(aManager, function() {
michael@0 930 is_in_discovery(aManager, MAIN_URL, true, false);
michael@0 931
michael@0 932 go_back(aManager);
michael@0 933
michael@0 934 waitForLoad(aManager, function() {
michael@0 935 is_in_discovery(aManager, SECOND_URL, true, true);
michael@0 936
michael@0 937 go_back(aManager);
michael@0 938
michael@0 939 waitForLoad(aManager, function() {
michael@0 940 is_in_discovery(aManager, MAIN_URL, true, true);
michael@0 941
michael@0 942 go_back(aManager);
michael@0 943
michael@0 944 wait_for_view_load(aManager, function(aManager) {
michael@0 945 is_in_list(aManager, "addons://list/plugin", false, true);
michael@0 946
michael@0 947 go_forward(aManager);
michael@0 948
michael@0 949 wait_for_view_load(aManager, function(aManager) {
michael@0 950 is_in_discovery(aManager, MAIN_URL, true, true);
michael@0 951
michael@0 952 waitForLoad(aManager, function() {
michael@0 953 is_in_discovery(aManager, SECOND_URL, true, true);
michael@0 954
michael@0 955 waitForLoad(aManager, function() {
michael@0 956 is_in_discovery(aManager, MAIN_URL, true, false);
michael@0 957
michael@0 958 close_manager(aManager, run_next_test);
michael@0 959 });
michael@0 960 go_forward(aManager);
michael@0 961 });
michael@0 962
michael@0 963 go_forward(aManager);
michael@0 964 });
michael@0 965 });
michael@0 966 });
michael@0 967 });
michael@0 968 });
michael@0 969 });
michael@0 970 });
michael@0 971 });
michael@0 972 });

mercurial