Bug 549648 - Add some browser-chrome tests for viewport support [r=vingtetun]
authorMark Finkle <mfinkle@mozilla.com>
Thu, 04 Mar 2010 15:05:17 -0500
changeset 66035 2410b8b816fdc832234c7a010cd7b09741a5a621
parent 66034 e1ab93b5f24f74ec1b3db266e2699b2eef932ac0
child 66036 36cbcff6335a596a15fd9ad094a38e618b366cf0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs549648
Bug 549648 - Add some browser-chrome tests for viewport support [r=vingtetun]
mobile/chrome/tests/Makefile.in
mobile/chrome/tests/browser_viewport.js
mobile/chrome/tests/browser_viewport_01.html
mobile/chrome/tests/browser_viewport_02.html
--- a/mobile/chrome/tests/Makefile.in
+++ b/mobile/chrome/tests/Makefile.in
@@ -49,16 +49,19 @@ include $(topsrcdir)/config/rules.mk
   browser_mainui.js \
   browser_tabs.js \
   browser_bookmarks.js \
   browser_bookmarks_star.js \
   browser_bookmarks_tags.js \
   browser_select.js \
   browser_rect.js \
   browser_FormAssistant.js \
+  browser_viewport.js \
   browser_blank_01.html \
   browser_blank_02.html \
   browser_select.html \
   browser_FormAssistant.html \
+  browser_viewport_01.html \
+  browser_viewport_02.html \
   $(NULL)
 
 libs:: $(_BROWSER_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_viewport.js
@@ -0,0 +1,113 @@
+let testURL_blank = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_01.html";
+let testURL_vport_01 = "chrome://mochikit/content/browser/mobile/chrome/browser_viewport_01.html";
+let testURL_vport_02 = "chrome://mochikit/content/browser/mobile/chrome/browser_viewport_02.html";
+
+let working_tab;
+
+//------------------------------------------------------------------------------
+// Entry point (must be named "test")
+function test() {
+  // This test is async
+  waitForExplicitFinish();
+
+  // Add new tab
+  working_tab = Browser.addTab(testURL_blank, true);
+  ok(working_tab, "Tab Opened");
+
+  // Check viewport load (need to check the tab "loading", not the document "loading")
+  waitFor(load_first_blank, function() { return working_tab.isLoading() == false; });
+}
+
+function load_first_blank() {
+  // Do sanity tests
+  var uri = working_tab.browser.currentURI.spec;
+  is(uri, testURL_blank, "URL Matches newly created Tab");
+
+  // Check viewport settings
+  ok(working_tab.browser.classList.contains("browser"), "Normal 'browser' class");
+  let style = window.getComputedStyle(working_tab.browser, null);
+  is(style.width, "800px", "Normal 'browser' width is 800 pixels");
+
+  // Load device-width page
+  BrowserUI.goToURI(testURL_vport_01);
+
+  // Check viewport load (need to check the tab "loading", not the document "loading")
+  waitFor(load_first_viewport, function() { return working_tab.isLoading() == false; });
+}
+
+function load_first_viewport() {
+  // Do sanity tests
+  var uri = working_tab.browser.currentURI.spec;
+  is(uri, testURL_vport_01, "URL Matches newly created Tab");
+
+  // Check viewport settings
+  ok(working_tab.browser.classList.contains("browser-viewport"), "Viewport 'browser-viewport' class");
+  let style = window.getComputedStyle(working_tab.browser, null);
+  is(style.width, window.innerWidth + "px", "Viewport device-width is equal to window.innerWidth");
+
+  is(Browser._browserView.getZoomLevel(), 1, "Viewport scale=1");
+
+  // Load device-width page
+  BrowserUI.goToURI(testURL_blank);
+
+  // Check viewport load (need to check the tab "loading", not the document "loading")
+  waitFor(load_second_blank, function() { return working_tab.isLoading() == false; });
+}
+
+function load_second_blank() {
+  // Do sanity tests
+  var uri = working_tab.browser.currentURI.spec;
+  is(uri, testURL_blank, "URL Matches newly created Tab");
+
+  // Check viewport settings
+  ok(working_tab.browser.classList.contains("browser"), "Normal 'browser' class");
+  let style = window.getComputedStyle(working_tab.browser, null);
+  is(style.width, "800px", "Normal 'browser' width is 800 pixels");
+
+  // Load width fixed page
+  BrowserUI.goToURI(testURL_vport_02);
+
+  // Check viewport load (need to check the tab "loading", not the document "loading")
+  waitFor(load_second_viewport, function() { return working_tab.isLoading() == false; });
+}
+
+function load_second_viewport() {
+  // Do sanity tests
+  var uri = working_tab.browser.currentURI.spec;
+  is(uri, testURL_vport_02, "URL Matches newly created Tab");
+
+  // Check viewport settings
+  ok(working_tab.browser.classList.contains("browser-viewport"), "Viewport 'browser-viewport' class");
+  let style = window.getComputedStyle(working_tab.browser, null);
+  is(style.width, "320px", "Viewport width=320");
+
+  is(Browser._browserView.getZoomLevel(), 1, "Viewport scale=1");
+
+  // Load device-width page
+  BrowserUI.goToURI(testURL_blank);
+
+  // Check viewport load (need to check the tab "loading", not the document "loading")
+  waitFor(load_third_blank, function() { return working_tab.isLoading() == false; });
+}
+
+function load_third_blank() {
+  // Do sanity tests
+  var uri = working_tab.browser.currentURI.spec;
+  is(uri, testURL_blank, "URL Matches newly created Tab");
+
+  // Check viewport settings
+  ok(working_tab.browser.classList.contains("browser"), "Normal 'browser' class");
+  let style = window.getComputedStyle(working_tab.browser, null);
+  is(style.width, "800px", "Normal 'browser' width is 800 pixels");
+
+  // Close down the test
+  test_close();
+}
+
+function test_close() {
+  // Close the tab
+  Browser.closeTab(working_tab);
+
+  // We must finialize the tests
+  finish();
+}
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_viewport_01.html
@@ -0,0 +1,10 @@
+<html>
+<head>
+    <title>Browser Viewport Page 01</title>
+    <meta name="viewport" content="width=device-width, initial-scale=1"/>
+</head>
+<body>
+    <p>Browser Viewport Page 01</p>
+    <p>width=device-width, initial-scale=1</p>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_viewport_02.html
@@ -0,0 +1,10 @@
+<html>
+<head>
+    <title>Browser Viewport Page 02</title>
+    <meta name="viewport" content="width=320, initial-scale=1"/>
+</head>
+<body>
+    <p>Browser Viewport Page 02</p>
+    <p>width=320</p>
+</body>
+</html>