Bug 1261299 - Add test for checking that the selected content/chrome text is properly sent up to the osx service menu code (nsChildView.mm). draft
authorJimmy Wang <jimmyw22@gmail.com>
Fri, 08 Jul 2016 11:38:16 -0400
changeset 401298 7b2c3e3d9b6cd5defec315fd67ee85f77c291d5a
parent 401297 845456afe9b4e04bffdb585b0e9307f3ebbf7ecc
child 401299 6d83ff4eb530843be75dfa9fc80a133939be2324
push id26424
push userjimmyw22@gmail.com
push dateTue, 16 Aug 2016 21:05:59 +0000
bugs1261299
milestone51.0a1
Bug 1261299 - Add test for checking that the selected content/chrome text is properly sent up to the osx service menu code (nsChildView.mm). MozReview-Commit-ID: 1gLTyNrxQ7E
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_bug1261299.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -210,16 +210,19 @@ skip-if = buildapp == 'mulet' # Bug 1066
 [browser_bug555767.js]
 [browser_bug559991.js]
 [browser_bug561636.js]
 skip-if = true # bug 1057615
 [browser_bug563588.js]
 [browser_bug565575.js]
 [browser_bug567306.js]
 subsuite = clipboard
+[browser_bug1261299.js]
+subsuite = clipboard
+skip-if = toolkit != "cocoa" # Because of tests for supporting Service Menu of macOS, bug 1261299
 [browser_bug575561.js]
 [browser_bug575830.js]
 [browser_bug577121.js]
 [browser_bug578534.js]
 [browser_bug579872.js]
 [browser_bug580638.js]
 [browser_bug580956.js]
 [browser_bug581242.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_bug1261299.js
@@ -0,0 +1,73 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Tests for Bug 1261299
+ * Test that the service menu code path is called properly and the
+ * current selection (transferable) is cached properly on the parent process.
+ */
+
+add_task(function* test_content_and_chrome_selection()
+{
+  let testPage =
+    'data:text/html,' +
+    '<textarea id="textarea">Write something here</textarea>';
+  let DOMWindowUtils = EventUtils._getDOMWindowUtils(window);
+  let selectedText;
+
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, testPage);
+  yield BrowserTestUtils.synthesizeMouse("#textarea", 0, 0, {}, gBrowser.selectedBrowser);
+  yield BrowserTestUtils.synthesizeKey("KEY_ArrowRight",
+      {shiftKey: true, ctrlKey: true, code: "ArrowRight"}, gBrowser.selectedBrowser);
+  selectedText = DOMWindowUtils.GetSelectionAsPlaintext();
+  is(selectedText, "Write something here", "The macOS services got the selected content text");
+
+  gURLBar.value = "test.mozilla.org";
+  yield gURLBar.focus();
+  yield BrowserTestUtils.synthesizeKey("KEY_ArrowRight",
+      {shiftKey: true, ctrlKey: true, code: "ArrowRight"}, gBrowser.selectedBrowser);
+  selectedText = DOMWindowUtils.GetSelectionAsPlaintext();
+  is(selectedText, "test.mozilla.org", "The macOS services got the selected chrome text");
+
+  yield BrowserTestUtils.removeTab(tab);
+});
+
+// Test switching active selection.
+// Each tab has a content selection and when you switch to that tab, its selection becomes
+// active aka the current selection.
+// Expect: The active selection is what is being sent to OSX service menu.
+
+add_task(function* test_active_selection_switches_properly()
+{
+  let testPage1 =
+    'data:text/html,' +
+    '<textarea id="textarea">Write something here</textarea>';
+  let testPage2 =
+    'data:text/html,' +
+    '<textarea id="textarea">Nothing available</textarea>';
+  let DOMWindowUtils = EventUtils._getDOMWindowUtils(window);
+  let selectedText;
+
+  let tab1 = yield BrowserTestUtils.openNewForegroundTab(gBrowser, testPage1);
+  yield BrowserTestUtils.synthesizeMouse("#textarea", 0, 0, {}, gBrowser.selectedBrowser);
+  yield BrowserTestUtils.synthesizeKey("KEY_ArrowRight",
+      {shiftKey: true, ctrlKey: true, code: "ArrowRight"}, gBrowser.selectedBrowser);
+
+  let tab2 = yield BrowserTestUtils.openNewForegroundTab(gBrowser, testPage2);
+  yield BrowserTestUtils.synthesizeMouse("#textarea", 0, 0, {}, gBrowser.selectedBrowser);
+  yield BrowserTestUtils.synthesizeKey("KEY_ArrowRight",
+      {shiftKey: true, ctrlKey: true, code: "ArrowRight"}, gBrowser.selectedBrowser);
+
+  yield BrowserTestUtils.switchTab(gBrowser, tab1);
+  selectedText = DOMWindowUtils.GetSelectionAsPlaintext();
+  is(selectedText, "Write something here", "The macOS services got the selected content text");
+
+  yield BrowserTestUtils.switchTab(gBrowser, tab2);
+  selectedText = DOMWindowUtils.GetSelectionAsPlaintext();
+  is(selectedText, "Nothing available", "The macOS services got the selected content text");
+
+  yield BrowserTestUtils.removeTab(tab1);
+  yield BrowserTestUtils.removeTab(tab2);
+});
\ No newline at end of file