2010-05-03 10:52:39 -07:00
|
|
|
var testURL_01 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_01.html";
|
|
|
|
var testURL_02 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_02.html";
|
|
|
|
|
|
|
|
// A queue to order the tests and a handle for each test
|
|
|
|
var gTests = [];
|
|
|
|
var gCurrentTest = null;
|
|
|
|
|
2010-06-25 21:28:39 -07:00
|
|
|
function pageLoaded(url) {
|
|
|
|
return function() {
|
2010-08-24 01:43:50 -07:00
|
|
|
let tab = gCurrentTest._currentTab;
|
2010-06-25 21:28:39 -07:00
|
|
|
return !tab.isLoading() && tab.browser.currentURI.spec == url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-03 10:52:39 -07:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Entry point (must be named "test")
|
|
|
|
function test() {
|
|
|
|
// The "runNextTest" approach is async, so we need to call "waitForExplicitFinish()"
|
|
|
|
// We call "finish()" when the tests are finished
|
|
|
|
waitForExplicitFinish();
|
2010-08-24 01:43:50 -07:00
|
|
|
|
2010-05-03 10:52:39 -07:00
|
|
|
// Start the tests
|
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Iterating tests by shifting test out one by one as runNextTest is called.
|
|
|
|
function runNextTest() {
|
|
|
|
// Run the next test until all tests completed
|
|
|
|
if (gTests.length > 0) {
|
|
|
|
gCurrentTest = gTests.shift();
|
|
|
|
info(gCurrentTest.desc);
|
|
|
|
gCurrentTest.run();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Cleanup. All tests are completed at this point
|
|
|
|
try {
|
|
|
|
// Add any cleanup code here
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
// We must finialize the tests
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Loading a page into the URLBar with VK_RETURN
|
|
|
|
gTests.push({
|
|
|
|
desc: "Loading a page into the URLBar with VK_RETURN",
|
2010-08-24 01:43:50 -07:00
|
|
|
_currentTab: null,
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
run: function() {
|
2010-08-24 01:43:50 -07:00
|
|
|
this._currentTab = Browser.addTab(testURL_01, true);
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
// Wait for the tab to load, then do the test
|
2010-06-25 21:28:39 -07:00
|
|
|
waitFor(gCurrentTest.onPageReady, pageLoaded(testURL_01));
|
2010-05-03 10:52:39 -07:00
|
|
|
},
|
2010-06-25 21:28:39 -07:00
|
|
|
|
2010-05-03 10:52:39 -07:00
|
|
|
onPageReady: function() {
|
|
|
|
// Test the mode
|
|
|
|
let urlIcons = document.getElementById("urlbar-icons");
|
|
|
|
is(urlIcons.getAttribute("mode"), "view", "URL Mode is set to 'view'");
|
|
|
|
|
|
|
|
// Test back button state
|
|
|
|
let back = document.getElementById("tool-back");
|
2010-08-24 01:43:50 -07:00
|
|
|
is(back.disabled, !gCurrentTest._currentTab.browser.canGoBack, "Back button check");
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
// Test forward button state
|
|
|
|
let forward = document.getElementById("tool-forward");
|
2010-08-24 01:43:50 -07:00
|
|
|
is(forward.disabled, !gCurrentTest._currentTab.browser.canGoForward, "Forward button check");
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
// Focus the url edit
|
2010-06-24 15:25:40 -07:00
|
|
|
let urlbarEdit = document.getElementById("urlbar-edit");
|
|
|
|
EventUtils.synthesizeMouse(urlbarEdit, urlbarEdit.clientWidth / 2, urlbarEdit.clientHeight / 2, {});
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
// Wait for the awesomebar to load, then do the test
|
|
|
|
window.addEventListener("popupshown", gCurrentTest.onFocusReady, false);
|
|
|
|
},
|
2010-08-24 01:43:50 -07:00
|
|
|
|
2010-05-03 10:52:39 -07:00
|
|
|
onFocusReady: function() {
|
|
|
|
window.removeEventListener("popupshown", gCurrentTest.onFocusReady, false);
|
|
|
|
// Test mode
|
|
|
|
let urlIcons = document.getElementById("urlbar-icons");
|
|
|
|
is(urlIcons.getAttribute("mode"), "edit", "URL Mode is set to 'edit'");
|
|
|
|
|
|
|
|
// Test back button state
|
|
|
|
let back = document.getElementById("tool-back");
|
2010-08-24 01:43:50 -07:00
|
|
|
is(back.disabled, !gCurrentTest._currentTab.browser.canGoBack, "Back button check");
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
// Test forward button state
|
|
|
|
let forward = document.getElementById("tool-forward");
|
2010-08-24 01:43:50 -07:00
|
|
|
is(forward.disabled, !gCurrentTest._currentTab.browser.canGoForward, "Forward button check");
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
// Check button states (url edit is focused)
|
|
|
|
let go = document.getElementById("tool-go");
|
|
|
|
let goStyle = window.getComputedStyle(go, null);
|
|
|
|
is(goStyle.visibility, "visible", "GO is visible");
|
|
|
|
|
|
|
|
let stop = document.getElementById("tool-stop");
|
|
|
|
let stopStyle = window.getComputedStyle(stop, null);
|
|
|
|
is(stopStyle.visibility, "collapse", "STOP is hidden");
|
|
|
|
|
|
|
|
let reload = document.getElementById("tool-reload");
|
|
|
|
let reloadStyle = window.getComputedStyle(reload, null);
|
|
|
|
is(reloadStyle.visibility, "collapse", "RELOAD is hidden");
|
|
|
|
|
|
|
|
// Send the string and press return
|
|
|
|
EventUtils.synthesizeString(testURL_02, window);
|
|
|
|
EventUtils.synthesizeKey("VK_RETURN", {}, window)
|
|
|
|
|
|
|
|
// Wait for the tab to load, then do the test
|
2010-06-25 21:28:39 -07:00
|
|
|
waitFor(gCurrentTest.onPageFinish, pageLoaded(testURL_02));
|
2010-05-03 10:52:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onPageFinish: function() {
|
|
|
|
let urlIcons = document.getElementById("urlbar-icons");
|
|
|
|
is(urlIcons.getAttribute("mode"), "view", "URL Mode is set to 'view'");
|
|
|
|
|
|
|
|
// Check button states (url edit is not focused)
|
|
|
|
let go = document.getElementById("tool-go");
|
|
|
|
let goStyle = window.getComputedStyle(go, null);
|
|
|
|
is(goStyle.visibility, "collapse", "GO is hidden");
|
|
|
|
|
|
|
|
let stop = document.getElementById("tool-stop");
|
|
|
|
let stopStyle = window.getComputedStyle(stop, null);
|
|
|
|
is(stopStyle.visibility, "collapse", "STOP is hidden");
|
|
|
|
|
|
|
|
let reload = document.getElementById("tool-reload");
|
|
|
|
let reloadStyle = window.getComputedStyle(reload, null);
|
|
|
|
is(reloadStyle.visibility, "visible", "RELOAD is visible");
|
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
let uri = gCurrentTest._currentTab.browser.currentURI.spec;
|
2010-05-03 10:52:39 -07:00
|
|
|
is(uri, testURL_02, "URL Matches newly created Tab");
|
|
|
|
|
|
|
|
// Go back in session
|
2010-08-24 01:43:50 -07:00
|
|
|
gCurrentTest._currentTab.browser.goBack();
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
// Wait for the tab to load, then do the test
|
2010-06-25 21:28:39 -07:00
|
|
|
waitFor(gCurrentTest.onPageBack, pageLoaded(testURL_01));
|
2010-05-03 10:52:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onPageBack: function() {
|
|
|
|
// Test back button state
|
|
|
|
let back = document.getElementById("tool-back");
|
2010-08-24 01:43:50 -07:00
|
|
|
is(back.disabled, !gCurrentTest._currentTab.browser.canGoBack, "Back button check");
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
// Test forward button state
|
|
|
|
let forward = document.getElementById("tool-forward");
|
2010-08-24 01:43:50 -07:00
|
|
|
is(forward.disabled, !gCurrentTest._currentTab.browser.canGoForward, "Forward button check");
|
|
|
|
|
|
|
|
Browser.closeTab(gCurrentTest._currentTab);
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
runNextTest();
|
2010-08-24 01:43:50 -07:00
|
|
|
}
|
2010-05-03 10:52:39 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Case: Loading a page into the URLBar with GO button
|
|
|
|
gTests.push({
|
|
|
|
desc: "Loading a page into the URLBar with GO button",
|
2010-08-24 01:43:50 -07:00
|
|
|
_currentTab: null,
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
run: function() {
|
2010-08-24 01:43:50 -07:00
|
|
|
this._currentTab = Browser.addTab(testURL_01, true);
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
// Wait for the tab to load, then do the test
|
2010-06-25 21:28:39 -07:00
|
|
|
waitFor(gCurrentTest.onPageReady, pageLoaded(testURL_01));
|
2010-05-03 10:52:39 -07:00
|
|
|
},
|
2010-08-24 01:43:50 -07:00
|
|
|
|
2010-05-03 10:52:39 -07:00
|
|
|
onPageReady: function() {
|
|
|
|
let urlIcons = document.getElementById("urlbar-icons");
|
|
|
|
is(urlIcons.getAttribute("mode"), "view", "URL Mode is set to 'view'");
|
|
|
|
|
|
|
|
// Focus the url edit
|
2010-06-24 15:25:40 -07:00
|
|
|
let urlbarEdit = document.getElementById("urlbar-edit");
|
|
|
|
EventUtils.synthesizeMouse(urlbarEdit, urlbarEdit.clientWidth / 2, urlbarEdit.clientHeight / 2, {});
|
2010-05-03 10:52:39 -07:00
|
|
|
|
|
|
|
// Wait for the awesomebar to load, then do the test
|
|
|
|
window.addEventListener("popupshown", gCurrentTest.onFocusReady, false);
|
|
|
|
},
|
2010-08-24 01:43:50 -07:00
|
|
|
|
2010-05-03 10:52:39 -07:00
|
|
|
onFocusReady: function() {
|
|
|
|
window.removeEventListener("popupshown", gCurrentTest.onFocusReady, false);
|
|
|
|
let urlIcons = document.getElementById("urlbar-icons");
|
|
|
|
is(urlIcons.getAttribute("mode"), "edit", "URL Mode is set to 'edit'");
|
|
|
|
|
|
|
|
// Check button states (url edit is focused)
|
|
|
|
let go = document.getElementById("tool-go");
|
|
|
|
let goStyle = window.getComputedStyle(go, null);
|
|
|
|
is(goStyle.visibility, "visible", "GO is visible");
|
|
|
|
|
|
|
|
let stop = document.getElementById("tool-stop");
|
|
|
|
let stopStyle = window.getComputedStyle(stop, null);
|
|
|
|
is(stopStyle.visibility, "collapse", "STOP is hidden");
|
|
|
|
|
|
|
|
let reload = document.getElementById("tool-reload");
|
|
|
|
let reloadStyle = window.getComputedStyle(reload, null);
|
|
|
|
is(reloadStyle.visibility, "collapse", "RELOAD is hidden");
|
|
|
|
|
|
|
|
EventUtils.synthesizeString(testURL_02, window);
|
|
|
|
EventUtils.synthesizeMouse(go, go.clientWidth / 2, go.clientHeight / 2, {});
|
|
|
|
|
|
|
|
// Wait for the tab to load, then do the test
|
2010-06-25 21:28:39 -07:00
|
|
|
waitFor(gCurrentTest.onPageFinish, pageLoaded(testURL_02));
|
2010-05-03 10:52:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onPageFinish: function() {
|
|
|
|
let urlIcons = document.getElementById("urlbar-icons");
|
|
|
|
is(urlIcons.getAttribute("mode"), "view", "URL Mode is set to 'view'");
|
|
|
|
|
|
|
|
// Check button states (url edit is not focused)
|
|
|
|
let go = document.getElementById("tool-go");
|
|
|
|
let goStyle = window.getComputedStyle(go, null);
|
|
|
|
is(goStyle.visibility, "collapse", "GO is hidden");
|
|
|
|
|
|
|
|
let stop = document.getElementById("tool-stop");
|
|
|
|
let stopStyle = window.getComputedStyle(stop, null);
|
|
|
|
is(stopStyle.visibility, "collapse", "STOP is hidden");
|
|
|
|
|
|
|
|
let reload = document.getElementById("tool-reload");
|
|
|
|
let reloadStyle = window.getComputedStyle(reload, null);
|
|
|
|
is(reloadStyle.visibility, "visible", "RELOAD is visible");
|
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
let uri = gCurrentTest._currentTab.browser.currentURI.spec;
|
2010-05-03 10:52:39 -07:00
|
|
|
is(uri, testURL_02, "URL Matches newly created Tab");
|
|
|
|
|
2010-08-24 01:43:50 -07:00
|
|
|
Browser.closeTab(gCurrentTest._currentTab);
|
2010-06-25 21:28:39 -07:00
|
|
|
|
2010-05-03 10:52:39 -07:00
|
|
|
runNextTest();
|
2010-06-25 21:28:39 -07:00
|
|
|
}
|
2010-05-03 10:52:39 -07:00
|
|
|
});
|