1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug556061.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; 1.9 +let testActionURL = "moz-action:switchtab," + testURL; 1.10 +testURL = gURLBar.trimValue(testURL); 1.11 +let testTab; 1.12 + 1.13 +function runNextTest() { 1.14 + if (tests.length) { 1.15 + let t = tests.shift(); 1.16 + waitForClipboard(t.expected, t.setup, function() { 1.17 + t.success(); 1.18 + runNextTest(); 1.19 + }, cleanup); 1.20 + } 1.21 + else { 1.22 + cleanup(); 1.23 + } 1.24 +} 1.25 + 1.26 +function cleanup() { 1.27 + gBrowser.removeTab(testTab); 1.28 + finish(); 1.29 +} 1.30 + 1.31 +let tests = [ 1.32 + { 1.33 + expected: testURL, 1.34 + setup: function() { 1.35 + gURLBar.value = testActionURL; 1.36 + gURLBar.valueIsTyped = true; 1.37 + is(gURLBar.value, testActionURL, "gURLBar.value starts with correct value"); 1.38 + 1.39 + // Focus the urlbar so we can select it all & copy 1.40 + gURLBar.focus(); 1.41 + gURLBar.select(); 1.42 + goDoCommand("cmd_copy"); 1.43 + }, 1.44 + success: function() { 1.45 + is(gURLBar.value, testActionURL, "gURLBar.value didn't change when copying"); 1.46 + } 1.47 + }, 1.48 + { 1.49 + expected: testURL.substring(0, 10), 1.50 + setup: function() { 1.51 + // Set selectionStart/End manually and make sure it matches the substring 1.52 + gURLBar.selectionStart = 0; 1.53 + gURLBar.selectionEnd = 10; 1.54 + goDoCommand("cmd_copy"); 1.55 + }, 1.56 + success: function() { 1.57 + is(gURLBar.value, testActionURL, "gURLBar.value didn't change when copying"); 1.58 + } 1.59 + }, 1.60 + { 1.61 + expected: testURL, 1.62 + setup: function() { 1.63 + // Setup for cut test... 1.64 + // Select all 1.65 + gURLBar.select(); 1.66 + goDoCommand("cmd_cut"); 1.67 + }, 1.68 + success: function() { 1.69 + is(gURLBar.value, "", "gURLBar.value is now empty"); 1.70 + } 1.71 + }, 1.72 + { 1.73 + expected: testURL.substring(testURL.length - 10, testURL.length), 1.74 + setup: function() { 1.75 + // Reset urlbar value 1.76 + gURLBar.value = testActionURL; 1.77 + gURLBar.valueIsTyped = true; 1.78 + // Sanity check that we have the right value 1.79 + is(gURLBar.value, testActionURL, "gURLBar.value starts with correct value"); 1.80 + 1.81 + // Now just select part of the value & cut that. 1.82 + gURLBar.selectionStart = testURL.length - 10; 1.83 + gURLBar.selectionEnd = testURL.length; 1.84 + goDoCommand("cmd_cut"); 1.85 + }, 1.86 + success: function() { 1.87 + is(gURLBar.value, testURL.substring(0, testURL.length - 10), "gURLBar.value has the correct value"); 1.88 + } 1.89 + } 1.90 +]; 1.91 + 1.92 +function test() { 1.93 + waitForExplicitFinish(); 1.94 + testTab = gBrowser.addTab(); 1.95 + gBrowser.selectedTab = testTab; 1.96 + 1.97 + // Kick off the testing 1.98 + runNextTest(); 1.99 +}