From 32ac9ae3363e37009ce14adb7ad6f88cba62c27d Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Fri, 22 Feb 2013 14:11:45 -0600 Subject: [PATCH] Bug 844113 - Add tests. r=mbrubeck --- browser/metro/base/tests/Makefile.in | 2 + .../base/tests/browser_context_menu_tests.js | 114 +++++++++++++++++- .../tests/browser_context_menu_tests_03.html | 54 +++++++++ browser/metro/base/tests/text-block.html | 64 ++++++++++ 4 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 browser/metro/base/tests/browser_context_menu_tests_03.html create mode 100644 browser/metro/base/tests/text-block.html diff --git a/browser/metro/base/tests/Makefile.in b/browser/metro/base/tests/Makefile.in index b91b90b26a9d..5b6d1104e470 100644 --- a/browser/metro/base/tests/Makefile.in +++ b/browser/metro/base/tests/Makefile.in @@ -26,6 +26,8 @@ BROWSER_TESTS = \ browser_context_menu_tests.js \ browser_context_menu_tests_01.html \ browser_context_menu_tests_02.html \ + browser_context_menu_tests_03.html \ + text-block.html \ $(NULL) BROWSER_TEST_RESOURCES = \ diff --git a/browser/metro/base/tests/browser_context_menu_tests.js b/browser/metro/base/tests/browser_context_menu_tests.js index b6365e0e13ec..978617df6d0d 100644 --- a/browser/metro/base/tests/browser_context_menu_tests.js +++ b/browser/metro/base/tests/browser_context_menu_tests.js @@ -26,7 +26,6 @@ function emptyClipboard() { .emptyClipboard(Ci.nsIClipboard.kGlobalClipboard); } -// Image context menu tests gTests.push({ desc: "text context menu", run: function test() { @@ -397,6 +396,119 @@ gTests.push({ } }); +gTests.push({ + desc: "tests for subframe positioning", + run: function test() { + info(chromeRoot + "browser_context_menu_tests_03.html"); + yield addTab(chromeRoot + "browser_context_menu_tests_03.html"); + + let win = Browser.selectedTab.browser.contentWindow; + + // Sometimes the context ui is visible, sometimes it isn't. + try { + yield waitForCondition(function () { + return ContextUI.isVisible; + }, 500, 50); + } catch (ex) {} + + ContextUI.dismiss(); + + let frame1 = win.document.getElementById("frame1"); + let link1 = frame1.contentDocument.getElementById("link1"); + + let promise = waitForEvent(document, "popupshown"); + sendContextMenuClickToElement(frame1.contentDocument.defaultView, link1, 85, 10); + yield promise; + ok(promise && !(promise instanceof Error), "promise error"); + + // should be visible + ok(ContextMenuUI._menuPopup._visible, "is visible"); + + ok(ContextMenuUI._panel.left > 375 && ContextMenuUI._panel.left < 390, "position"); + ok(ContextMenuUI._panel.top > 235 && ContextMenuUI._panel.top < 245, "position"); + + promise = waitForEvent(document, "popuphidden"); + ContextMenuUI.hide(); + yield promise; + ok(promise && !(promise instanceof Error), "promise error"); + + frame1.contentDocument.defaultView.scrollBy(0, 200); + + promise = waitForEvent(document, "popupshown"); + sendContextMenuClickToElement(frame1.contentDocument.defaultView, link1, 85, 10); + yield promise; + ok(promise && !(promise instanceof Error), "promise error"); + + // should be visible + ok(ContextMenuUI._menuPopup._visible, "is visible"); + + ok(ContextMenuUI._panel.left > 375 && ContextMenuUI._panel.left < 390, "position"); + ok(ContextMenuUI._panel.top > 35 && ContextMenuUI._panel.top < 45, "position"); + + promise = waitForEvent(document, "popuphidden"); + ContextMenuUI.hide(); + yield promise; + ok(promise && !(promise instanceof Error), "promise error"); + + let rlink1 = win.document.getElementById("rlink1"); + + promise = waitForEvent(document, "popupshown"); + sendContextMenuClickToElement(win, rlink1, 40, 10); + yield promise; + ok(promise && !(promise instanceof Error), "promise error"); + + // should be visible + ok(ContextMenuUI._menuPopup._visible, "is visible"); + + ok(ContextMenuUI._panel.left > 730 && ContextMenuUI._panel.left < 745, "position"); + ok(ContextMenuUI._panel.top > 600 && ContextMenuUI._panel.top < 610, "position"); + + promise = waitForEvent(document, "popuphidden"); + ContextMenuUI.hide(); + yield promise; + ok(promise && !(promise instanceof Error), "promise error"); + + win.scrollBy(0, 200); + + promise = waitForEvent(document, "popupshown"); + sendContextMenuClickToElement(win, rlink1, 40, 10); + yield promise; + ok(promise && !(promise instanceof Error), "promise error"); + + // should be visible + ok(ContextMenuUI._menuPopup._visible, "is visible"); + + ok(ContextMenuUI._panel.left > 730 && ContextMenuUI._panel.left < 745, "position"); + ok(ContextMenuUI._panel.top > 400 && ContextMenuUI._panel.top < 410, "position"); + + promise = waitForEvent(document, "popuphidden"); + ContextMenuUI.hide(); + yield promise; + ok(promise && !(promise instanceof Error), "promise error"); + + let link2 = frame1.contentDocument.getElementById("link2"); + + promise = waitForEvent(document, "popupshown"); + sendContextMenuClickToElement(frame1.contentDocument.defaultView, link2, 85, 10); + yield promise; + ok(promise && !(promise instanceof Error), "promise error"); + + // should be visible + ok(ContextMenuUI._menuPopup._visible, "is visible"); + + info(ContextMenuUI._panel.left); + info(ContextMenuUI._panel.top); + + ok(ContextMenuUI._panel.left > 380 && ContextMenuUI._panel.left < 390, "position"); + ok(ContextMenuUI._panel.top > 170 && ContextMenuUI._panel.top < 185, "position"); + + promise = waitForEvent(document, "popuphidden"); + ContextMenuUI.hide(); + yield promise; + ok(promise && !(promise instanceof Error), "promise error"); + } +}); + function test() { runTests(); } diff --git a/browser/metro/base/tests/browser_context_menu_tests_03.html b/browser/metro/base/tests/browser_context_menu_tests_03.html new file mode 100644 index 000000000000..4cb4597fbe72 --- /dev/null +++ b/browser/metro/base/tests/browser_context_menu_tests_03.html @@ -0,0 +1,54 @@ + + + + + + + + +Hello there. hello there. +
+ + + +
+
+Hello there. hello there. +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ \ No newline at end of file diff --git a/browser/metro/base/tests/text-block.html b/browser/metro/base/tests/text-block.html new file mode 100644 index 000000000000..72123cd263df --- /dev/null +++ b/browser/metro/base/tests/text-block.html @@ -0,0 +1,64 @@ + + + + + + +
+

(start of paragraph) + Alice was beginning to get very (break)
+ tired of sitting by her sister on the bank, and of having nothing to do: once or twice she (span) + (start of span) had peeped into the book her sister was reading (end of span), + but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice + `without pictures or conversation?' (break)
+ (end of paragraph)

+ (in between paragraphs) +

(start of paragraph) + Alice was beginning to get very + tired of sitting by her sister on the bank, and of having nothing to do: once or twice she + had peeped into the book her sister was reading, but it had no pictures or conversations + in it, `and what is the use of a book,' thought Alice `without pictures or conversation?'(break)
+ (end of paragraph)

+ +

(start of paragraph) + So she was considering in her own mind (as well as she could, for the hot day made her + feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth + the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink + eyes ran close by her.
+

+ +

+ There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of + the way to hear the Rabbit say to itself, `Oh dear! Oh dear! I shall be late!' (when she + thought it over afterwards, it occurred to her that she ought to have wondered at this, + but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH + OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her + feet, for it flashed across her mind that she had never before seen a rabbit with either a + waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across + the field after it, and fortunately was just in time to see it pop down a large + rabbit-hole under the hedge.
+
+ In another moment down went Alice after it, never once considering how in the world she + was to get out again.
+
+ The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly + down, so suddenly that Alice had not a moment to think about stopping herself before she + found herself falling down a very deep well.
+
(start of paragraph) + Either the well was very deep, or she fell very slowly, for she had plenty of time as she + went down to look about her and to wonder what was going to happen next. First, she tried + to look down and make out what she was coming to, but it was too dark to see anything; + then she looked at the sides of the well, and noticed that they were filled with cupboards + and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a + jar from one of the shelves as she passed; it was labelled `ORANGE MARMALADE', but to her + great disappointment it was empty: she did not like to drop the jar for fear of killing + somebody, so managed to put it into one of the cupboards as she fell past it.
+
+ `Well!' thought Alice to herself, `after such a fall as this, I shall think nothing of + tumbling down stairs! How brave they'll all think me at home! Why, I wouldn't say anything + about it, even if I fell off the top of the house!' (Which was very likely true.)
+
+ Down, down, down. +
+

+ \ No newline at end of file