michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; michael@0: let testActionURL = "moz-action:switchtab," + testURL; michael@0: testURL = gURLBar.trimValue(testURL); michael@0: let testTab; michael@0: michael@0: function runNextTest() { michael@0: if (tests.length) { michael@0: let t = tests.shift(); michael@0: waitForClipboard(t.expected, t.setup, function() { michael@0: t.success(); michael@0: runNextTest(); michael@0: }, cleanup); michael@0: } michael@0: else { michael@0: cleanup(); michael@0: } michael@0: } michael@0: michael@0: function cleanup() { michael@0: gBrowser.removeTab(testTab); michael@0: finish(); michael@0: } michael@0: michael@0: let tests = [ michael@0: { michael@0: expected: testURL, michael@0: setup: function() { michael@0: gURLBar.value = testActionURL; michael@0: gURLBar.valueIsTyped = true; michael@0: is(gURLBar.value, testActionURL, "gURLBar.value starts with correct value"); michael@0: michael@0: // Focus the urlbar so we can select it all & copy michael@0: gURLBar.focus(); michael@0: gURLBar.select(); michael@0: goDoCommand("cmd_copy"); michael@0: }, michael@0: success: function() { michael@0: is(gURLBar.value, testActionURL, "gURLBar.value didn't change when copying"); michael@0: } michael@0: }, michael@0: { michael@0: expected: testURL.substring(0, 10), michael@0: setup: function() { michael@0: // Set selectionStart/End manually and make sure it matches the substring michael@0: gURLBar.selectionStart = 0; michael@0: gURLBar.selectionEnd = 10; michael@0: goDoCommand("cmd_copy"); michael@0: }, michael@0: success: function() { michael@0: is(gURLBar.value, testActionURL, "gURLBar.value didn't change when copying"); michael@0: } michael@0: }, michael@0: { michael@0: expected: testURL, michael@0: setup: function() { michael@0: // Setup for cut test... michael@0: // Select all michael@0: gURLBar.select(); michael@0: goDoCommand("cmd_cut"); michael@0: }, michael@0: success: function() { michael@0: is(gURLBar.value, "", "gURLBar.value is now empty"); michael@0: } michael@0: }, michael@0: { michael@0: expected: testURL.substring(testURL.length - 10, testURL.length), michael@0: setup: function() { michael@0: // Reset urlbar value michael@0: gURLBar.value = testActionURL; michael@0: gURLBar.valueIsTyped = true; michael@0: // Sanity check that we have the right value michael@0: is(gURLBar.value, testActionURL, "gURLBar.value starts with correct value"); michael@0: michael@0: // Now just select part of the value & cut that. michael@0: gURLBar.selectionStart = testURL.length - 10; michael@0: gURLBar.selectionEnd = testURL.length; michael@0: goDoCommand("cmd_cut"); michael@0: }, michael@0: success: function() { michael@0: is(gURLBar.value, testURL.substring(0, testURL.length - 10), "gURLBar.value has the correct value"); michael@0: } michael@0: } michael@0: ]; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: testTab = gBrowser.addTab(); michael@0: gBrowser.selectedTab = testTab; michael@0: michael@0: // Kick off the testing michael@0: runNextTest(); michael@0: }