Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; |
michael@0 | 6 | let testActionURL = "moz-action:switchtab," + testURL; |
michael@0 | 7 | testURL = gURLBar.trimValue(testURL); |
michael@0 | 8 | let testTab; |
michael@0 | 9 | |
michael@0 | 10 | function runNextTest() { |
michael@0 | 11 | if (tests.length) { |
michael@0 | 12 | let t = tests.shift(); |
michael@0 | 13 | waitForClipboard(t.expected, t.setup, function() { |
michael@0 | 14 | t.success(); |
michael@0 | 15 | runNextTest(); |
michael@0 | 16 | }, cleanup); |
michael@0 | 17 | } |
michael@0 | 18 | else { |
michael@0 | 19 | cleanup(); |
michael@0 | 20 | } |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function cleanup() { |
michael@0 | 24 | gBrowser.removeTab(testTab); |
michael@0 | 25 | finish(); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | let tests = [ |
michael@0 | 29 | { |
michael@0 | 30 | expected: testURL, |
michael@0 | 31 | setup: function() { |
michael@0 | 32 | gURLBar.value = testActionURL; |
michael@0 | 33 | gURLBar.valueIsTyped = true; |
michael@0 | 34 | is(gURLBar.value, testActionURL, "gURLBar.value starts with correct value"); |
michael@0 | 35 | |
michael@0 | 36 | // Focus the urlbar so we can select it all & copy |
michael@0 | 37 | gURLBar.focus(); |
michael@0 | 38 | gURLBar.select(); |
michael@0 | 39 | goDoCommand("cmd_copy"); |
michael@0 | 40 | }, |
michael@0 | 41 | success: function() { |
michael@0 | 42 | is(gURLBar.value, testActionURL, "gURLBar.value didn't change when copying"); |
michael@0 | 43 | } |
michael@0 | 44 | }, |
michael@0 | 45 | { |
michael@0 | 46 | expected: testURL.substring(0, 10), |
michael@0 | 47 | setup: function() { |
michael@0 | 48 | // Set selectionStart/End manually and make sure it matches the substring |
michael@0 | 49 | gURLBar.selectionStart = 0; |
michael@0 | 50 | gURLBar.selectionEnd = 10; |
michael@0 | 51 | goDoCommand("cmd_copy"); |
michael@0 | 52 | }, |
michael@0 | 53 | success: function() { |
michael@0 | 54 | is(gURLBar.value, testActionURL, "gURLBar.value didn't change when copying"); |
michael@0 | 55 | } |
michael@0 | 56 | }, |
michael@0 | 57 | { |
michael@0 | 58 | expected: testURL, |
michael@0 | 59 | setup: function() { |
michael@0 | 60 | // Setup for cut test... |
michael@0 | 61 | // Select all |
michael@0 | 62 | gURLBar.select(); |
michael@0 | 63 | goDoCommand("cmd_cut"); |
michael@0 | 64 | }, |
michael@0 | 65 | success: function() { |
michael@0 | 66 | is(gURLBar.value, "", "gURLBar.value is now empty"); |
michael@0 | 67 | } |
michael@0 | 68 | }, |
michael@0 | 69 | { |
michael@0 | 70 | expected: testURL.substring(testURL.length - 10, testURL.length), |
michael@0 | 71 | setup: function() { |
michael@0 | 72 | // Reset urlbar value |
michael@0 | 73 | gURLBar.value = testActionURL; |
michael@0 | 74 | gURLBar.valueIsTyped = true; |
michael@0 | 75 | // Sanity check that we have the right value |
michael@0 | 76 | is(gURLBar.value, testActionURL, "gURLBar.value starts with correct value"); |
michael@0 | 77 | |
michael@0 | 78 | // Now just select part of the value & cut that. |
michael@0 | 79 | gURLBar.selectionStart = testURL.length - 10; |
michael@0 | 80 | gURLBar.selectionEnd = testURL.length; |
michael@0 | 81 | goDoCommand("cmd_cut"); |
michael@0 | 82 | }, |
michael@0 | 83 | success: function() { |
michael@0 | 84 | is(gURLBar.value, testURL.substring(0, testURL.length - 10), "gURLBar.value has the correct value"); |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | ]; |
michael@0 | 88 | |
michael@0 | 89 | function test() { |
michael@0 | 90 | waitForExplicitFinish(); |
michael@0 | 91 | testTab = gBrowser.addTab(); |
michael@0 | 92 | gBrowser.selectedTab = testTab; |
michael@0 | 93 | |
michael@0 | 94 | // Kick off the testing |
michael@0 | 95 | runNextTest(); |
michael@0 | 96 | } |