diff options
Diffstat (limited to 'browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul')
-rw-r--r-- | browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul b/browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul new file mode 100644 index 000000000..b1d73017f --- /dev/null +++ b/browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul @@ -0,0 +1,170 @@ +<?xml version="1.0"?> + +<!-- Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ --> + +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" + type="text/css"?> + +<?xml-stylesheet href="chrome://browser/skin/places/editBookmarkOverlay.css"?> +<?xml-stylesheet href="chrome://browser/content/places/places.css"?> +<?xml-stylesheet href="chrome://browser/skin/places/places.css"?> + +<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?> +<?xul-overlay href="chrome://browser/content/places/editBookmarkOverlay.xul"?> + +<!DOCTYPE window [ + <!ENTITY % editBookmarkOverlayDTD SYSTEM "chrome://browser/locale/places/editBookmarkOverlay.dtd"> + %editBookmarkOverlayDTD; +]> + +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + title="Bug 631374 - Editing tags in the selector scrolls up the listbox" + onload="runTest();"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> + <script type="application/javascript" + src="chrome://browser/content/places/editBookmarkOverlay.js"/> + + <body xmlns="http://www.w3.org/1999/xhtml" /> + + <vbox id="editBookmarkPanelContent"/> + + <script type="application/javascript"> + <![CDATA[ + + /** + * This test checks that editing tags doesn't scroll the tags selector + * listbox to wrong positions. + */ + + function runTest() { + SimpleTest.waitForExplicitFinish(); + + Task.spawn(function* () { + let bs = PlacesUtils.bookmarks; + + let tags = ["a", "b", "c", "d", "e", "f", "g", + "h", "i", "l", "m", "n", "o", "p"]; + + // Add a bookmark and tag it. + let uri1 = Services.io.newURI("http://www1.mozilla.org/", null, null); + let bm1 = yield bs.insert({ + parentGuid: bs.toolbarGuid, + index: bs.DEFAULT_INDEX, + type: bs.TYPE_BOOKMARK, + title: "mozilla", + url: uri1.spec + }); + PlacesUtils.tagging.tagURI(uri1, tags); + + // Add a second bookmark so that tags won't disappear when unchecked. + let uri2 = Services.io.newURI("http://www2.mozilla.org/", null, null); + let bm2 = yield bs.insert({ + parentGuid: bs.toolbarGuid, + index: bs.DEFAULT_INDEX, + type: bs.TYPE_BOOKMARK, + title: "mozilla", + url: uri2.spec + }); + PlacesUtils.tagging.tagURI(uri2, tags); + + // Init panel. + ok(gEditItemOverlay, "gEditItemOverlay is in context"); + let node1 = yield PlacesUIUtils.promiseNodeLikeFromFetchInfo(bm1); + gEditItemOverlay.initPanel({ node: node1 }); + ok(gEditItemOverlay.initialized, "gEditItemOverlay is initialized"); + + yield openTagSelector(); + let tagsSelector = document.getElementById("editBMPanel_tagsSelector"); + + // Go by two so there is some untouched tag in the middle. + for (let i = 8; i < tags.length; i += 2) { + tagsSelector.selectedIndex = i; + let listItem = tagsSelector.selectedItem; + isnot(listItem, null, "Valid listItem found"); + + tagsSelector.ensureElementIsVisible(listItem); + let visibleIndex = tagsSelector.getIndexOfFirstVisibleRow(); + + ok(listItem.checked, "Item is checked " + i); + let selectedTag = listItem.label; + + // Uncheck the tag. + listItem.checked = false; + is(visibleIndex, tagsSelector.getIndexOfFirstVisibleRow(), + "Scroll position did not change"); + + // The listbox is rebuilt, so we have to get the new element. + let newItem = tagsSelector.selectedItem; + isnot(newItem, null, "Valid new listItem found"); + ok(!newItem.checked, "New listItem is unchecked " + i); + is(newItem.label, selectedTag, "Correct tag is still selected"); + + // Check the tag. + newItem.checked = true; + is(visibleIndex, tagsSelector.getIndexOfFirstVisibleRow(), + "Scroll position did not change"); + } + + // Remove the second bookmark, then nuke some of the tags. + yield bs.remove(bm2.guid); + + // Doing this backwords tests more interesting paths. + for (let i = tags.length - 1; i >= 0 ; i -= 2) { + tagsSelector.selectedIndex = i; + let listItem = tagsSelector.selectedItem; + isnot(listItem, null, "Valid listItem found"); + + tagsSelector.ensureElementIsVisible(listItem); + let firstVisibleTag = tags[tagsSelector.getIndexOfFirstVisibleRow()]; + + ok(listItem.checked, "Item is checked " + i); + let selectedTag = listItem.label; + + // Uncheck the tag. + listItem.checked = false; + + // Ensure the first visible tag is still visible in the list. + let firstVisibleIndex = tagsSelector.getIndexOfFirstVisibleRow(); + let lastVisibleIndex = firstVisibleIndex + tagsSelector.getNumberOfVisibleRows() -1; + let expectedTagIndex = tags.indexOf(firstVisibleTag); + ok(expectedTagIndex >= firstVisibleIndex && + expectedTagIndex <= lastVisibleIndex, + "Scroll position is correct"); + + // The listbox is rebuilt, so we have to get the new element. + let newItem = tagsSelector.selectedItem; + isnot(newItem, null, "Valid new listItem found"); + ok(newItem.checked, "New listItem is checked " + i); + is(tagsSelector.selectedItem.label, + tags[Math.min(i + 1, tags.length - 2)], + "The next tag is now selected"); + } + + // Cleanup. + yield bs.remove(bm1.guid); + }).then(SimpleTest.finish).catch(alert); + } + + function openTagSelector() { + // Wait for the tags selector to be open. + let promise = new Promise(resolve => { + let row = document.getElementById("editBMPanel_tagsSelectorRow"); + row.addEventListener("DOMAttrModified", function onAttrModified() { + row.removeEventListener("DOMAttrModified", onAttrModified); + resolve(); + }); + }); + + // Open the tags selector. + document.getElementById("editBMPanel_tagsSelectorExpander").doCommand(); + + return promise; + } + ]]> + </script> + +</window> |