Bug 684558 - browser-chrome test for escape key handling [r=mfinkle]

--HG--
rename : mobile/chrome/tests/browser_blank_02.html => mobile/chrome/tests/browser_blank_03.html
This commit is contained in:
Matt Brubeck 2011-09-30 21:30:49 -07:00
parent e5775bb636
commit bc91e6a049
3 changed files with 122 additions and 0 deletions

View File

@ -61,9 +61,11 @@ _BROWSER_FILES = \
browser_awesomescreen.js \
browser_blank_01.html \
browser_blank_02.html \
browser_blank_03.html \
browser_bookmarks.js \
browser_contacts.js \
browser_dragger.js \
browser_escape.js \
browser_find.js \
browser_focus.html \
browser_focus.js \

View File

@ -0,0 +1,6 @@
<html>
<title>Browser Blank Page 03</title>
<body>
<p>Browser Blank Page 03</p>
</body>
</html>

View File

@ -0,0 +1,114 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Mobile Browser.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Matt Brubeck <mbrubeck@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
"use strict";
const url1 = baseURI + "browser_blank_01.html";
const url2 = baseURI + "browser_blank_02.html";
const url3 = baseURI + "browser_blank_03.html";
let tab1, tab2;
function test() {
waitForExplicitFinish();
testGoBack();
registerCleanupFunction(closeTabs);
}
function testGoBack() {
tab1 = Browser.addTab("about:blank", true);
tab2 = Browser.addTab("about:blank", true, tab1);
let browser = tab2.browser;
// Load each of these URLs, then use escape to step backward through them.
let urls = [url1, url2, url3];
let i = 0, step = 1;
let expectedURI;
function loadNextPage() {
expectedURI = urls[i];
if (step == 1) {
// go forward
Browser.loadURI(expectedURI);
} else {
// go back by pressing the escape key
Browser.selectedBrowser.focus();
EventUtils.synthesizeKey("VK_ESCAPE", {type: "keypress"}, window);
}
}
browser.messageManager.addMessageListener("pageshow", function listener(aMessage) {
let uri = browser.currentURI.spec;
if (uri == "about:blank") {
loadNextPage();
return;
}
is(uri, expectedURI, "Page " + i + " loaded");
if (i == urls.length - 1)
step = -1; // start going back when we get to the end
i += step;
if (i >= 0) {
loadNextPage();
//setTimeout(loadNextPage, 1000);
} else {
// All done. Go to the next test.
browser.messageManager.removeMessageListener("pageshow", listener);
closeTabs();
testReturnToOwner();
}
});
}
function testReturnToOwner() {
tab1 = Browser.addTab("about:blank", true);
tab2 = Browser.addTab("about:blank", true, tab1);
is(Browser.selectedTab, tab2, "tab2 is selected");
EventUtils.sendKey("ESCAPE", window);
is(Browser.selectedTab, tab1, "tab1 is selected");
closeTabs();
finish();
}
function closeTabs() {
try {
Browser.closeTab(tab1);
Browser.closeTab(tab2);
} finally {
tab1 = tab2 = null;
}
}