summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-28 05:35:10 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-28 05:35:10 +0000
commit491b5525ceda62ae4c1f2f38d57460c9ac6ee2c6 (patch)
tree24ddb1221d2b55ca032c8157e482ccfd009c0bf2 /chrome
parent7632306dce9282980437c3982cfb97bebc5684ec (diff)
downloadchromium_src-491b5525ceda62ae4c1f2f38d57460c9ac6ee2c6.zip
chromium_src-491b5525ceda62ae4c1f2f38d57460c9ac6ee2c6.tar.gz
chromium_src-491b5525ceda62ae4c1f2f38d57460c9ac6ee2c6.tar.bz2
Revert "Revert "Split ExtensionApiTest.Tabs into several smaller tests and re-enable.""
This reverts commit d0777a59efc9678cde43a2932badc43735d212c3. TBR=mpcomplete@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64206 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_tabs_apitest.cc28
-rw-r--r--chrome/test/data/extensions/api_test/tabs/basics/crud.html203
-rw-r--r--chrome/test/data/extensions/api_test/tabs/basics/events.html179
-rw-r--r--chrome/test/data/extensions/api_test/tabs/basics/manifest.json1
-rw-r--r--chrome/test/data/extensions/api_test/tabs/basics/move.html85
-rw-r--r--chrome/test/data/extensions/api_test/tabs/basics/relative.html9
-rw-r--r--chrome/test/data/extensions/api_test/tabs/basics/relative_urls.html46
-rw-r--r--chrome/test/data/extensions/api_test/tabs/basics/tabs_util.js32
-rw-r--r--chrome/test/data/extensions/api_test/tabs/basics/test.html2
-rw-r--r--chrome/test/data/extensions/api_test/tabs/basics/test.js486
10 files changed, 547 insertions, 524 deletions
diff --git a/chrome/browser/extensions/extension_tabs_apitest.cc b/chrome/browser/extensions/extension_tabs_apitest.cc
index a81c78b..043e23b 100644
--- a/chrome/browser/extensions/extension_tabs_apitest.cc
+++ b/chrome/browser/extensions/extension_tabs_apitest.cc
@@ -9,14 +9,6 @@
#include "chrome/browser/profile.h"
#include "chrome/common/pref_names.h"
-#if defined(OS_WIN)
-// This test times out on win.
-// http://crbug.com/58269
-#define MAYBE_Tabs DISABLED_Tabs
-#else
-#define MAYBE_Tabs Tabs
-#endif
-
// Possible race in ChromeURLDataManager. http://crbug.com/59198
#if defined(OS_MACOSX) || defined(OS_LINUX)
#define MAYBE_TabOnRemoved DISABLED_TabOnRemoved
@@ -24,7 +16,7 @@
#define MAYBE_TabOnRemoved TabOnRemoved
#endif
-IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Tabs) {
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Tabs) {
ASSERT_TRUE(test_server()->Start());
// The test creates a tab and checks that the URL of the new tab
@@ -33,7 +25,23 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Tabs) {
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kHomePageIsNewTabPage, true);
- ASSERT_TRUE(RunExtensionTest("tabs/basics")) << message_;
+ ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud.html")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabMove) {
+ ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "move.html")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabEvents) {
+ ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "events.html")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabRelativeURLs) {
+ ASSERT_TRUE(test_server()->Start());
+ ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "relative_urls.html"))
+ << message_;
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabGetCurrent) {
diff --git a/chrome/test/data/extensions/api_test/tabs/basics/crud.html b/chrome/test/data/extensions/api_test/tabs/basics/crud.html
new file mode 100644
index 0000000..0b7bac2
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/tabs/basics/crud.html
@@ -0,0 +1,203 @@
+<script src="tabs_util.js"></script>
+
+<script>
+var firstWindowId;
+var secondWindowId;
+var testTabId;
+
+chrome.test.runTests([
+ function getSelected() {
+ chrome.tabs.getSelected(null, pass(function(tab) {
+ assertEq(location.href, tab.url);
+ assertEq(location.href, tab.title);
+ firstWindowId = tab.windowId;
+ }));
+ },
+
+ function create() {
+ chrome.tabs.create({"windowId" : firstWindowId, "selected" : false},
+ pass(function(tab){
+ assertEq(1, tab.index);
+ assertEq(firstWindowId, tab.windowId);
+ assertEq(false, tab.selected);
+ assertEq("chrome://newtab/", tab.url);
+ }));
+ },
+
+ function createInOtherWindow() {
+ chrome.windows.create({}, pass(function(win) {
+ // Create a tab in the older window.
+ chrome.tabs.create({"windowId" : firstWindowId, "selected" : false},
+ pass(function(tab) {
+ assertEq(firstWindowId, tab.windowId);
+ }));
+ // Create a tab in this new window.
+ chrome.tabs.create({"windowId" : win.id}, pass(function(tab) {
+ assertEq(win.id, tab.windowId);
+ }));
+ }));
+ },
+
+ function createAtIndex() {
+ chrome.tabs.create({"windowId" : firstWindowId, "index" : 1},
+ pass(function(tab) {
+ assertEq(1, tab.index);
+ }));
+ },
+
+ function createSelected() {
+ chrome.tabs.create({"windowId" : firstWindowId, "selected" : true},
+ pass(function(tab) {
+ assertTrue(tab.selected);
+ chrome.tabs.getSelected(firstWindowId, pass(function(selectedTab) {
+ assertEq(tab.id, selectedTab.id);
+ }));
+ }));
+ },
+
+ function createWindowWithDefaultTab() {
+ var verify_default = function() {
+ return pass(function(win) {
+ assertEq(1, win.tabs.length);
+ assertEq("chrome://newtab/", win.tabs[0].url);
+ });
+ };
+
+ // Make sure the window always has the NTP when no URL is supplied.
+ chrome.windows.create({}, verify_default());
+ chrome.windows.create({url:[]}, verify_default());
+ },
+
+ function setupTwoWindows() {
+ createWindow(["about:blank", "chrome://newtab/", pageUrl("a")], {},
+ pass(function(winId, tabIds) {
+ firstWindowId = winId;
+ testTabId = tabIds[2];
+
+ createWindow(["chrome://newtab/", pageUrl("b")], {},
+ pass(function(winId, tabIds) {
+ secondWindowId = winId;
+ }));
+ }));
+ },
+
+ function getAllInWindow() {
+ chrome.tabs.getAllInWindow(firstWindowId,
+ pass(function(tabs) {
+ assertEq(3, tabs.length);
+ for (var i = 0; i < tabs.length; i++) {
+ assertEq(firstWindowId, tabs[i].windowId);
+ assertEq(i, tabs[i].index);
+
+ // The first tab should be selected
+ assertEq((i == 0), tabs[i].selected);
+ }
+ assertEq("about:blank", tabs[0].url);
+ assertEq("chrome://newtab/", tabs[1].url);
+ assertEq(pageUrl("a"), tabs[2].url);
+ }));
+
+ chrome.tabs.getAllInWindow(secondWindowId,
+ pass(function(tabs) {
+ assertEq(2, tabs.length);
+ for (var i = 0; i < tabs.length; i++) {
+ assertEq(secondWindowId, tabs[i].windowId);
+ assertEq(i, tabs[i].index);
+ }
+ assertEq("chrome://newtab/", tabs[0].url);
+ assertEq(pageUrl("b"), tabs[1].url);
+ }));
+ },
+
+ /*
+ :: sigh :: This test used to be disabled for unrelated reasons, but while it
+ was, the underlying functionality was broken. crbug.com/60795
+ function getAllInWindowNullArg() {
+ chrome.tabs.getAllInWindow(null, pass(function(tabs) {
+ assertEq(2, tabs.length);
+ assertEq(secondWindowId, tabs[0].windowId);
+ }));
+ },
+ */
+
+ function update() {
+ chrome.tabs.get(testTabId, pass(function(tab) {
+ assertEq(pageUrl("a"), tab.url);
+ // Update url.
+ chrome.tabs.update(testTabId, {"url": pageUrl("c")},
+ pass(function(tab){
+ chrome.test.assertEq(pageUrl("c"), tab.url);
+ // Check url.
+ chrome.tabs.get(testTabId, pass(function(tab) {
+ assertEq(pageUrl("c"), tab.url);
+ }));
+ }));
+ }));
+ },
+
+ function updateSelect() {
+ chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
+ assertEq(true, tabs[0].selected);
+ assertEq(false, tabs[1].selected);
+ assertEq(false, tabs[2].selected);
+ // Select tab[1].
+ chrome.tabs.update(tabs[1].id, {selected: true},
+ pass(function(tab1){
+ // Check update of tab[1].
+ chrome.test.assertEq(true, tab1.selected);
+ chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
+ assertEq(true, tabs[1].selected);
+ assertEq(false, tabs[2].selected);
+ // Select tab[2].
+ chrome.tabs.update(tabs[2].id,
+ {selected: true},
+ pass(function(tab2){
+ // Check update of tab[2].
+ chrome.test.assertEq(true, tab2.selected);
+ chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
+ assertEq(false, tabs[1].selected);
+ assertEq(true, tabs[2].selected);
+ }));
+ }));
+ }));
+ }));
+ }));
+ },
+
+ /* Sadly, this has also regressed. crbug.com/60802.
+ function detectLanguage() {
+ chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
+ chrome.tabs.detectLanguage(tabs[0].id, pass(function(lang) {
+ assertEq("en", lang);
+ }));
+ }));
+ },
+ */
+
+ function windowCreate() {
+ chrome.windows.create({type: "popup"}, pass(function(window) {
+ assertEq("popup", window.type);
+ assertTrue(!window.incognito);
+ }));
+ chrome.windows.create({incognito: true}, pass(function(window) {
+ // This extension is not incognito-enabled, so it shouldn't be able to
+ // see the incognito window.
+ assertEq(null, window);
+ }));
+ },
+
+ /* Disabled -- see http://bugs.chromium.org/58229.
+ function windowSetFocused() {
+ chrome.windows.getCurrent(function(oldWin) {
+ chrome.windows.create({}, function(newWin) {
+ assertTrue(newWin.focused);
+ chrome.windows.update(oldWin.id, {focused:true});
+ chrome.windows.get(oldWin.id, pass(function(oldWin2) {
+ assertTrue(oldWin2.focused);
+ }));
+ });
+ });
+ },
+ */
+]);
+</script>
diff --git a/chrome/test/data/extensions/api_test/tabs/basics/events.html b/chrome/test/data/extensions/api_test/tabs/basics/events.html
new file mode 100644
index 0000000..7cfaec7
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/tabs/basics/events.html
@@ -0,0 +1,179 @@
+<script src="tabs_util.js"></script>
+
+<script>
+var testTabId;
+var otherTabId;
+var firstWindowId;
+var secondWindowId;
+
+chrome.test.runTests([
+ function init() {
+ chrome.tabs.getSelected(null, pass(function(tab) {
+ testTabId = tab.id;
+ firstWindowId = tab.windowId;
+ }));
+ },
+
+ function tabsOnCreated() {
+ chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) {
+ assertEq(pageUrl("f"), tab.url);
+ otherTabId = tab.id;
+ // TODO(jstritar): http://crbug.com/59194 tab.selected is always false
+ // when passed into chrome.tabs.onCreated listener
+ //assertEq(true, tab.selected);
+ });
+
+ chrome.tabs.create({"windowId": firstWindowId, "url": pageUrl("f"),
+ "selected": true}, pass(function(tab) {}));
+ },
+
+ function tabsOnUpdatedIgnoreTabArg() {
+ // A third argument was added to the onUpdated event callback.
+ // Test that an event handler which ignores this argument works.
+ var onUpdatedCompleted = chrome.test.listenForever(chrome.tabs.onUpdated,
+ function(tabid, changeInfo) {
+ if (tabid == otherTabId && changeInfo.status == "complete") {
+ onUpdatedCompleted();
+ }
+ }
+ );
+
+ chrome.tabs.update(otherTabId, {"url": pageUrl("f")}, pass());
+ },
+
+ function tabsOnUpdated() {
+ var onUpdatedCompleted = chrome.test.listenForever(
+ chrome.tabs.onUpdated,
+ function(tabid, changeInfo, tab) {
+ // |tab| contains the id of the tab it describes.
+ // Test that |tabid| matches this id.
+ assertEq(tabid, tab.id);
+
+ // If |changeInfo| has a status property, than
+ // it should match the status of the tab in |tab|.
+ if (changeInfo.status) {
+ assertEq(changeInfo.status, tab.status);
+ }
+
+ if (tabid == otherTabId && changeInfo.status == "complete") {
+ onUpdatedCompleted();
+ }
+ }
+ );
+
+ chrome.tabs.update(otherTabId, {"url": pageUrl("f")}, pass());
+ },
+
+ function tabsOnMoved() {
+ chrome.test.listenOnce(chrome.tabs.onMoved, function(tabid, info) {
+ assertEq(otherTabId, tabid);
+ });
+
+ chrome.tabs.move(otherTabId, {"index": 0}, pass());
+ },
+
+ function tabsOnSelectionChanged() {
+ chrome.test.listenOnce(chrome.tabs.onSelectionChanged,
+ function(tabid, info) {
+ assertEq(testTabId, tabid);
+ }
+ );
+
+ chrome.tabs.update(testTabId, {"selected": true}, pass());
+ },
+
+ function setupTabsOnAttachDetach() {
+ createWindow([""], {}, pass(function(winId, tabIds) {
+ secondWindowId = winId;
+ }));
+ },
+
+ function tabsOnAttached() {
+ function moveAndListen(tabId, properties, callback) {
+ chrome.test.listenOnce(chrome.tabs.onAttached,
+ function(testTabId, info) {
+ // Ensure notification is correct.
+ assertEq(testTabId, tabId);
+ assertEq(properties.windowId, info.newWindowId);
+ assertEq(properties.index, info.newPosition);
+ if (callback)
+ callback();
+ });
+ chrome.tabs.move(tabId, properties);
+ };
+
+ // Move tab to second window, then back to first.
+ // The original tab/window configuration should be restored.
+ // tabsOnDetached() depends on it.
+ moveAndListen(testTabId, {"windowId": secondWindowId, "index": 0},
+ pass(function() {
+ moveAndListen(testTabId, {"windowId": firstWindowId, "index": 1});
+ }));
+ },
+
+ function tabsOnDetached() {
+ function moveAndListen(tabId, oldWindowId, oldIndex, properties,
+ callback) {
+ chrome.test.listenOnce(chrome.tabs.onDetached,
+ function(detachedTabId, info) {
+ // Ensure notification is correct.
+ assertEq(detachedTabId, tabId);
+ assertEq(oldWindowId, info.oldWindowId);
+ assertEq(oldIndex, info.oldPosition);
+ if (callback)
+ callback();
+ });
+ chrome.tabs.move(tabId, properties);
+ };
+
+ // Move tab to second window, then back to first.
+ moveAndListen(testTabId, firstWindowId, 1,
+ {"windowId": secondWindowId, "index": 0}, pass(function() {
+ moveAndListen(testTabId, secondWindowId, 0,
+ {"windowId": firstWindowId, "index": 1});
+ }));
+ },
+
+ function windowsOnCreated() {
+ chrome.test.listenOnce(chrome.windows.onCreated, function(window) {
+ assertTrue(window.width > 0);
+ assertTrue(window.height > 0);
+ assertEq("normal", window.type);
+ assertTrue(!window.incognito);
+ windowEventsWindow = window;
+ chrome.tabs.getAllInWindow(window.id, pass(function(tabs) {
+ assertEq(pageUrl("a"), tabs[0].url);
+ }));
+ });
+
+ chrome.windows.create({"url": pageUrl("a")}, pass(function(tab) {}));
+ },
+
+ function windowsOnFocusChanged() {
+ // This test doesn't work on mac because the Chromium app never gets
+ // brought to the front. See: crbug.com/60963.
+ //
+ // It also doesn't work on Chrome OS for unknown reasons.
+ // See: crbug.com/61035.
+ if (navigator.platform.toLowerCase().indexOf("mac") == 0 ||
+ /\bCrOS\b/.test(navigator.userAgent)) {
+ chrome.test.succeed();
+ return;
+ }
+
+ chrome.windows.getCurrent(pass(function(windowA) {
+ chrome.windows.create({}, pass(function(windowB) {
+ chrome.windows.update(windowA.id, {focused: true}, pass(function() {
+ chrome.windows.update(windowB.id, {focused: true}, pass(function() {
+ chrome.test.listenOnce(chrome.windows.onFocusChanged,
+ function(changedWindowId) {
+ assertEq(windowEventsWindow.id, changedWindowId);
+ });
+ chrome.windows.remove(windowB.id);
+ }));
+ }));
+ }));
+ }));
+ }
+]);
+</script>
diff --git a/chrome/test/data/extensions/api_test/tabs/basics/manifest.json b/chrome/test/data/extensions/api_test/tabs/basics/manifest.json
index 0ffa68f..59ed72e 100644
--- a/chrome/test/data/extensions/api_test/tabs/basics/manifest.json
+++ b/chrome/test/data/extensions/api_test/tabs/basics/manifest.json
@@ -2,6 +2,5 @@
"name": "chrome.tabs",
"version": "0.1",
"description": "end-to-end browser test for chrome.tabs API",
- "background_page": "test.html",
"permissions": ["tabs"]
}
diff --git a/chrome/test/data/extensions/api_test/tabs/basics/move.html b/chrome/test/data/extensions/api_test/tabs/basics/move.html
new file mode 100644
index 0000000..9df94f4
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/tabs/basics/move.html
@@ -0,0 +1,85 @@
+<script src="tabs_util.js"></script>
+
+<script>
+var firstWindowId;
+var secondWindowId;
+var moveTabIds = {};
+
+chrome.test.runTests([
+ // Do a series of moves so that we get the following
+ //
+ // Before:
+ // Window1: (newtab),a,b,c,d,e
+ // Window2: (newtab)
+ //
+ // After:
+ // Window1: (newtab),a,e,c
+ // Window2: b,(newtab),d
+ function setupLetterPages() {
+ var pages = ["chrome://newtab/", pageUrl('a'), pageUrl('b'),
+ pageUrl('c'), pageUrl('d'), pageUrl('e')];
+ createWindow(pages, {}, pass(function(winId, tabIds) {
+ firstWindowId = winId;
+ moveTabIds['a'] = tabIds[1];
+ moveTabIds['b'] = tabIds[2];
+ moveTabIds['c'] = tabIds[3];
+ moveTabIds['d'] = tabIds[4];
+ moveTabIds['e'] = tabIds[5];
+ createWindow(["chrome://newtab/"], {}, pass(function(winId, tabIds) {
+ secondWindowId = winId;
+ }));
+ chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
+ assertEq(pages.length, tabs.length);
+ for (var i in tabs) {
+ assertEq(pages[i], tabs[i].url);
+ }
+ }));
+ }));
+ },
+
+ function move() {
+ // Check that the tab/window state is what we expect after doing moves.
+ function checkMoveResults() {
+ chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
+ assertEq(4, tabs.length);
+ assertEq("chrome://newtab/", tabs[0].url);
+ assertEq(pageUrl("a"), tabs[1].url);
+ assertEq(pageUrl("e"), tabs[2].url);
+ assertEq(pageUrl("c"), tabs[3].url);
+
+ chrome.tabs.getAllInWindow(secondWindowId, pass(function(tabs) {
+ assertEq(3, tabs.length);
+ assertEq(pageUrl("b"), tabs[0].url);
+ assertEq("chrome://newtab/", tabs[1].url);
+ assertEq(pageUrl("d"), tabs[2].url);
+ }));
+ }));
+ }
+
+ chrome.tabs.move(moveTabIds['b'], {"windowId": secondWindowId, "index": 0},
+ pass(function(tabB) {
+ chrome.test.assertEq(0, tabB.index);
+ chrome.tabs.move(moveTabIds['e'], {"index": 2},
+ pass(function(tabE) {
+ chrome.test.assertEq(2, tabE.index);
+ chrome.tabs.move(moveTabIds['d'], {"windowId": secondWindowId,
+ "index": 2}, pass(function(tabD) {
+ chrome.test.assertEq(2, tabD.index);
+ checkMoveResults();
+ }));
+ }));
+ }));
+ },
+
+ function remove() {
+ chrome.tabs.remove(moveTabIds["d"], pass(function() {
+ chrome.tabs.getAllInWindow(secondWindowId,
+ pass(function(tabs) {
+ assertEq(2, tabs.length);
+ assertEq(pageUrl("b"), tabs[0].url);
+ assertEq("chrome://newtab/", tabs[1].url);
+ }));
+ }));
+ }
+]);
+</script>
diff --git a/chrome/test/data/extensions/api_test/tabs/basics/relative.html b/chrome/test/data/extensions/api_test/tabs/basics/relative.html
index 5a9e6ee8..30c4a2d 100644
--- a/chrome/test/data/extensions/api_test/tabs/basics/relative.html
+++ b/chrome/test/data/extensions/api_test/tabs/basics/relative.html
@@ -2,8 +2,13 @@
<head>
<script>
window.onload = function() {
- chrome.extension.getBackgroundPage().relativePageLoaded();
+ chrome.extension.getViews({type:"tab"}).forEach(function(view) {
+ if (view.relativePageLoaded) {
+ view.relativePageLoaded();
+ break;
+ }
+ });
}
</script>
</head>
-</html> \ No newline at end of file
+</html>
diff --git a/chrome/test/data/extensions/api_test/tabs/basics/relative_urls.html b/chrome/test/data/extensions/api_test/tabs/basics/relative_urls.html
new file mode 100644
index 0000000..f554399
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/tabs/basics/relative_urls.html
@@ -0,0 +1,46 @@
+<script src="tabs_util.js"></script>
+
+<script>
+var firstWindowId;
+var relativePageLoaded;
+
+chrome.test.runTests([
+ function setupRelativeUrlTests() {
+ createWindow(["about:blank"], {}, pass(function(winId, tabIds) {
+ firstWindowId = winId;
+ }));
+ },
+
+ function relativeUrlTestsTabsCreate() {
+ // Will be called from relative.html
+ relativePageLoaded = chrome.test.callbackAdded();
+ var createCompleted = chrome.test.callbackAdded();
+
+ chrome.tabs.create({windowId: firstWindowId, url: 'relative.html'},
+ function(tab){
+ testTabId = tab.id;
+ createCompleted();
+ }
+ );
+ },
+
+ function relativeUrlTestsTabsUpdate() {
+ // Will be called from relative.html
+ relativePageLoaded = chrome.test.callbackAdded();
+
+ chrome.tabs.update(testTabId, {url: pageUrl("a")}, function(tab) {
+ chrome.test.assertEq(pageUrl("a"), tab.url);
+ chrome.tabs.update(tab.id, {url: "relative.html"}, function(tab) {
+ });
+ });
+ },
+
+ function relativeUrlTestsWindowCreate() {
+ // Will be called from relative.html
+ relativePageLoaded = chrome.test.callbackAdded();
+
+ chrome.windows.create({url: "relative.html"});
+ }
+
+]);
+</script>
diff --git a/chrome/test/data/extensions/api_test/tabs/basics/tabs_util.js b/chrome/test/data/extensions/api_test/tabs/basics/tabs_util.js
index 9f13dd9..9b1a9ba 100644
--- a/chrome/test/data/extensions/api_test/tabs/basics/tabs_util.js
+++ b/chrome/test/data/extensions/api_test/tabs/basics/tabs_util.js
@@ -1,26 +1,13 @@
-// Utility functions to help with tabs/windows testing.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
-// Removes current windows and creates one window with tabs set to
-// the urls in the array |tabUrls|. At least one url must be specified.
-// The |callback| should look like function(windowId, tabIds) {...}.
-function setupWindow(tabUrls, callback) {
- createWindow(tabUrls, {}, function(winId, tabIds) {
- // Remove all other windows.
- var removedCount = 0;
- chrome.windows.getAll({}, function(windows) {
- for (var i in windows) {
- if (windows[i].id != winId) {
- chrome.windows.remove(windows[i].id, function() {
- removedCount++;
- if (removedCount == windows.length - 1)
- callback(winId, tabIds);
- });
- }
- }
- if (windows.length == 1)
- callback(winId, tabIds);
- });
- });
+var pass = chrome.test.callbackPass;
+var assertEq = chrome.test.assertEq;
+var assertTrue = chrome.test.assertTrue;
+
+function pageUrl(letter) {
+ return chrome.extension.getURL(letter + ".html");
}
// Creates one window with tabs set to the urls in the array |tabUrls|.
@@ -67,4 +54,3 @@ function waitForAllTabs(callback) {
}
waitForTabs();
}
-
diff --git a/chrome/test/data/extensions/api_test/tabs/basics/test.html b/chrome/test/data/extensions/api_test/tabs/basics/test.html
deleted file mode 100644
index 54f4ab7..0000000
--- a/chrome/test/data/extensions/api_test/tabs/basics/test.html
+++ /dev/null
@@ -1,2 +0,0 @@
-<script src="tabs_util.js"></script>
-<script src="test.js"></script>
diff --git a/chrome/test/data/extensions/api_test/tabs/basics/test.js b/chrome/test/data/extensions/api_test/tabs/basics/test.js
deleted file mode 100644
index 3297bdf..0000000
--- a/chrome/test/data/extensions/api_test/tabs/basics/test.js
+++ /dev/null
@@ -1,486 +0,0 @@
-// tabs api test
-// browser_tests.exe --gtest_filter=ExtensionApiTest.Tabs
-
-// We have a bunch of places where we need to remember some state from one
-// test (or setup code) to subsequent tests.
-var firstWindowId = null;
-var secondWindowId = null;
-var firstTabIndex = null;
-var testTabId = null;
-
-var windowEventsWindow = null;
-var moveTabIds = {};
-
-var pass = chrome.test.callbackPass;
-var assertEq = chrome.test.assertEq;
-var assertTrue = chrome.test.assertTrue;
-
-function pageUrl(letter) {
- return chrome.extension.getURL(letter + ".html");
-}
-
-chrome.test.runTests([
- function getSelected() {
- chrome.tabs.getSelected(null, pass(function(tab) {
- assertEq("about:blank", tab.url);
- assertEq("about:blank", tab.title);
- firstWindowId = tab.windowId;
- firstTabIndex = tab.index;
- }));
- },
-
- function create() {
- chrome.tabs.create({"windowId" : firstWindowId, "selected" : false},
- pass(function(tab){
- assertTrue(tab.index > firstTabIndex);
- assertEq(firstWindowId, tab.windowId);
- assertEq(false, tab.selected);
- assertEq("chrome://newtab/", tab.url);
- }));
- },
-
- function createInOtherWindow() {
- chrome.windows.create({}, pass(function(win) {
- // The newly created window is now the currentWindow.
- // Create a tab in the older window.
- chrome.tabs.create({"windowId" : firstWindowId, "selected" : false},
- pass(function(tab) {
- assertEq(firstWindowId, tab.windowId);
- }));
- // Create a tab in this new window.
- chrome.tabs.create({"windowId" : win.id}, pass(function(tab) {
- assertEq(win.id, tab.windowId);
- }));
- }));
- },
-
- function createAtIndex() {
- chrome.tabs.create({"windowId" : firstWindowId, "index" : 1},
- pass(function(tab) {
- assertEq(1, tab.index);
- }));
- },
-
- function createSelected() {
- chrome.tabs.create({"windowId" : firstWindowId, "selected" : true},
- pass(function(tab) {
- assertTrue(tab.selected);
- chrome.tabs.getSelected(firstWindowId, pass(function(selectedTab) {
- assertEq(tab.id, selectedTab.id);
- }));
- }));
- },
-
- function createWindowWithDefaultTab() {
- var verify_default = function() {
- return pass(function(win) {
- assertEq(1, win.tabs.length);
- assertEq("chrome://newtab/", win.tabs[0].url);
- });
- };
-
- // Make sure the window always has the NTP when no URL is supplied.
- chrome.windows.create({}, verify_default());
- chrome.windows.create({url:[]}, verify_default());
- },
-
- function setupTwoWindows() {
- setupWindow(["about:blank", "chrome://newtab/", pageUrl("a")],
- pass(function(winId, tabIds) {
- firstWindowId = winId;
- testTabId = tabIds[2];
-
- createWindow(["chrome://newtab/", pageUrl("b")], {},
- pass(function(winId, tabIds) {
- secondWindowId = winId;
- }));
- }));
- },
-
- function getAllInWindow() {
- chrome.tabs.getAllInWindow(firstWindowId,
- pass(function(tabs) {
- assertEq(3, tabs.length);
- for (var i = 0; i < tabs.length; i++) {
- assertEq(firstWindowId, tabs[i].windowId);
- assertEq(i, tabs[i].index);
-
- // The first tab should be selected
- assertEq((i == 0), tabs[i].selected);
- }
- assertEq("about:blank", tabs[0].url);
- assertEq("chrome://newtab/", tabs[1].url);
- assertEq(pageUrl("a"), tabs[2].url);
- }));
-
- chrome.tabs.getAllInWindow(secondWindowId,
- pass(function(tabs) {
- assertEq(2, tabs.length);
- for (var i = 0; i < tabs.length; i++) {
- assertEq(secondWindowId, tabs[i].windowId);
- assertEq(i, tabs[i].index);
- }
- assertEq("chrome://newtab/", tabs[0].url);
- assertEq(pageUrl("b"), tabs[1].url);
- }));
- },
-
- /* TODO: Enable this test when crbug.com/28055 is fixed. This bug causes a
- newly created window not to be set as the current window, if
- Chrome was not the foreground window when the create call was made.
- function getAllInWindowNullArg() {
- chrome.tabs.getAllInWindow(null, pass(function(tabs) {
- assertEq(2, tabs.length);
- assertEq(secondWindowId, tabs[0].windowId);
- }));
- }, */
-
- function update() {
- chrome.tabs.get(testTabId, pass(function(tab) {
- assertEq(pageUrl("a"), tab.url);
- // Update url.
- chrome.tabs.update(testTabId, {"url": pageUrl("c")},
- pass(function(tab){
- chrome.test.assertEq(pageUrl("c"), tab.url);
- // Check url.
- chrome.tabs.get(testTabId, pass(function(tab) {
- assertEq(pageUrl("c"), tab.url);
- }));
- }));
- }));
- },
-
- function updateSelect() {
- chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
- assertEq(true, tabs[0].selected);
- assertEq(false, tabs[1].selected);
- assertEq(false, tabs[2].selected);
- // Select tab[1].
- chrome.tabs.update(tabs[1].id, {selected: true},
- pass(function(tab1){
- // Check update of tab[1].
- chrome.test.assertEq(true, tab1.selected);
- chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
- assertEq(true, tabs[1].selected);
- assertEq(false, tabs[2].selected);
- // Select tab[2].
- chrome.tabs.update(tabs[2].id,
- {selected: true},
- pass(function(tab2){
- // Check update of tab[2].
- chrome.test.assertEq(true, tab2.selected);
- chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
- assertEq(false, tabs[1].selected);
- assertEq(true, tabs[2].selected);
- }));
- }));
- }));
- }));
- }));
- },
-
- // Do a series of moves so that we get the following
- //
- // Before:
- // Window1: (newtab),a,b,c,d,e
- // Window2: (newtab)
- //
- // After:
- // Window1: (newtab),a,e,c
- // Window2: b,(newtab),d
- function setupLetterPages() {
- var pages = ["chrome://newtab/", pageUrl('a'), pageUrl('b'),
- pageUrl('c'), pageUrl('d'), pageUrl('e')];
- setupWindow(pages, pass(function(winId, tabIds) {
- firstWindowId = winId;
- moveTabIds['a'] = tabIds[1];
- moveTabIds['b'] = tabIds[2];
- moveTabIds['c'] = tabIds[3];
- moveTabIds['d'] = tabIds[4];
- moveTabIds['e'] = tabIds[5];
- createWindow(["chrome://newtab/"], {}, pass(function(winId, tabIds) {
- secondWindowId = winId;
- }));
- chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
- assertEq(pages.length, tabs.length);
- for (var i in tabs) {
- assertEq(pages[i], tabs[i].url);
- }
- }));
- }));
- },
-
- function move() {
- // Check that the tab/window state is what we expect after doing moves.
- function checkMoveResults()
- {
- chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
- assertEq(4, tabs.length);
- assertEq("chrome://newtab/", tabs[0].url);
- assertEq(pageUrl("a"), tabs[1].url);
- assertEq(pageUrl("e"), tabs[2].url);
- assertEq(pageUrl("c"), tabs[3].url);
-
- chrome.tabs.getAllInWindow(secondWindowId, pass(function(tabs) {
- assertEq(3, tabs.length);
- assertEq(pageUrl("b"), tabs[0].url);
- assertEq("chrome://newtab/", tabs[1].url);
- assertEq(pageUrl("d"), tabs[2].url);
- }));
- }));
- }
-
- chrome.tabs.move(moveTabIds['b'], {"windowId": secondWindowId, "index": 0},
- pass(function(tabB) {
- chrome.test.assertEq(0, tabB.index);
- chrome.tabs.move(moveTabIds['e'], {"index": 2},
- pass(function(tabE) {
- chrome.test.assertEq(2, tabE.index);
- chrome.tabs.move(moveTabIds['d'], {"windowId": secondWindowId,
- "index": 2}, pass(function(tabD) {
- chrome.test.assertEq(2, tabD.index);
- checkMoveResults();
- }));
- }));
- }));
- },
-
- function remove() {
- chrome.tabs.remove(moveTabIds["d"], pass(function() {
- chrome.tabs.getAllInWindow(secondWindowId,
- pass(function(tabs) {
- assertEq(2, tabs.length);
- assertEq(pageUrl("b"), tabs[0].url);
- assertEq("chrome://newtab/", tabs[1].url);
- }));
- }));
- },
-
- /*
- // TODO(jcampan): http://crbug.com/30662 the detection language library
- // crashes on some sites and has been temporarily disabled.
- function detectLanguage() {
- chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
- chrome.tabs.detectLanguage(tabs[0].id, pass(function(lang) {
- assertEq("en", lang);
- }));
- }));
- },
- */
-
- function tabsOnCreated() {
- chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) {
- assertEq(pageUrl("f"), tab.url);
- // TODO(jstritar): http://crbug.com/59194 tab.selected is always false
- // when passed into chrome.tabs.onCreated listener
- //assertEq(true, tab.selected);
- });
-
- chrome.tabs.create({"windowId": firstWindowId, "url": pageUrl("f"),
- "selected": true}, pass(function(tab) {}));
- },
-
- function tabsOnUpdatedIgnoreTabArg() {
- // A third argument was added to the onUpdated event callback.
- // Test that an event handler which ignores this argument works.
- var onUpdatedCompleted = chrome.test.listenForever(chrome.tabs.onUpdated,
- function(tabid, changeInfo) {
- if (tabid == moveTabIds['a'] && changeInfo.status == "complete") {
- onUpdatedCompleted();
- }
- }
- );
-
- chrome.tabs.update(moveTabIds['a'], {"url": pageUrl("f")}, pass());
- },
-
- function tabsOnUpdated() {
- var onUpdatedCompleted = chrome.test.listenForever(
- chrome.tabs.onUpdated,
- function(tabid, changeInfo, tab) {
- // |tab| contains the id of the tab it describes.
- // Test that |tabid| matches this id.
- assertEq(tabid, tab.id);
-
- // If |changeInfo| has a status property, than
- // it should match the status of the tab in |tab|.
- if (changeInfo.status) {
- assertEq(changeInfo.status, tab.status);
- }
-
- if (tabid == moveTabIds['a'] && changeInfo.status == "complete") {
- onUpdatedCompleted();
- }
- }
- );
-
- chrome.tabs.update(moveTabIds['a'], {"url": pageUrl("f")}, pass());
- },
-
- function tabsOnMoved() {
- chrome.test.listenOnce(chrome.tabs.onMoved, function(tabid, info) {
- assertEq(moveTabIds['a'], tabid);
- });
-
- chrome.tabs.move(moveTabIds['a'], {"index": 0}, pass());
- },
-
- function tabsOnSelectionChanged() {
- chrome.test.listenOnce(chrome.tabs.onSelectionChanged,
- function(tabid, info) {
- assertEq(moveTabIds['c'], tabid);
- }
- );
-
- chrome.tabs.update(moveTabIds['c'], {"selected": true},
- pass());
- },
-
- function setupTabsOnAttachDetach()
- {
- setupWindow(["", ""], pass(function(winId, tabIds) {
- firstWindowId = winId;
- testTabId = tabIds[1];
- createWindow([""], {}, pass(function(winId, tabIds) {
- secondWindowId = winId;
- }));
- }));
- },
-
- function tabsOnAttached() {
- function moveAndListen(tabId, properties, callback) {
- chrome.test.listenOnce(chrome.tabs.onAttached,
- function(testTabId, info) {
- // Ensure notification is correct.
- assertEq(testTabId, tabId);
- assertEq(properties.windowId, info.newWindowId);
- assertEq(properties.index, info.newPosition);
- if (callback)
- callback();
- });
- chrome.tabs.move(tabId, properties);
- };
-
- // Move tab to second window, then back to first.
- // The original tab/window configuration should be restored.
- // tabsOnDetached() depends on it.
- moveAndListen(testTabId, {"windowId": secondWindowId, "index": 0},
- pass(function() {
- moveAndListen(testTabId, {"windowId": firstWindowId, "index": 1});
- }));
- },
-
- function tabsOnDetached() {
- function moveAndListen(tabId, oldWindowId, oldIndex, properties,
- callback) {
- chrome.test.listenOnce(chrome.tabs.onDetached,
- function(detachedTabId, info) {
- // Ensure notification is correct.
- assertEq(detachedTabId, tabId);
- assertEq(oldWindowId, info.oldWindowId);
- assertEq(oldIndex, info.oldPosition);
- if (callback)
- callback();
- });
- chrome.tabs.move(tabId, properties);
- };
-
- // Move tab to second window, then back to first.
- moveAndListen(testTabId, firstWindowId, 1,
- {"windowId": secondWindowId, "index": 0}, pass(function() {
- moveAndListen(testTabId, secondWindowId, 0,
- {"windowId": firstWindowId, "index": 1});
- }));
- },
-
- function setupRelativeUrlTests() {
- setupWindow(["about:blank"], pass(function(winId, tabIds) {
- firstWindowId = winId;
- }));
- },
-
- function relativeUrlTestsTabsCreate() {
- // Will be called from relative.html
- window.relativePageLoaded = chrome.test.callbackAdded();
- var createCompleted = chrome.test.callbackAdded();
-
- chrome.tabs.create({windowId: firstWindowId, url: 'relative.html'},
- function(tab){
- testTabId = tab.id;
- createCompleted();
- }
- );
- },
-
- function relativeUrlTestsTabsUpdate() {
- // Will be called from relative.html
- window.relativePageLoaded = chrome.test.callbackAdded();
-
- chrome.tabs.update(testTabId, {url: pageUrl("a")}, function(tab) {
- chrome.test.assertEq(pageUrl("a"), tab.url);
- chrome.tabs.update(tab.id, {url: "relative.html"}, function(tab) {
- });
- });
- },
-
- function relativeUrlTestsWindowCreate() {
- // Will be called from relative.html
- window.relativePageLoaded = chrome.test.callbackAdded();
-
- chrome.windows.create({url: "relative.html"});
- },
-
- function windowCreate() {
- chrome.windows.create({type: "popup"}, pass(function(window) {
- assertEq("popup", window.type);
- assertTrue(!window.incognito);
- }));
- chrome.windows.create({incognito: true}, pass(function(window) {
- // This extension is not incognito-enabled, so it shouldn't be able to
- // see the incognito window.
- assertEq(null, window);
- }));
- },
-
- function windowsOnCreated() {
- chrome.test.listenOnce(chrome.windows.onCreated, function(window) {
- assertTrue(window.width > 0);
- assertTrue(window.height > 0);
- assertEq("normal", window.type);
- assertTrue(!window.incognito);
- windowEventsWindow = window;
- chrome.tabs.getAllInWindow(window.id, pass(function(tabs) {
- assertEq(pageUrl("a"), tabs[0].url);
- }));
- });
-
- chrome.windows.create({"url": pageUrl("a")}, pass(function(tab) {}));
- },
-
- /* Disabled -- see http://bugs.chromium.org/58229.
- function windowSetFocused() {
- chrome.windows.getCurrent(function(oldWin) {
- chrome.windows.create({}, function(newWin) {
- assertTrue(newWin.focused);
- chrome.windows.update(oldWin.id, {focused:true});
- chrome.windows.get(oldWin.id, pass(function(oldWin2) {
- assertTrue(oldWin2.focused);
- }));
- });
- });
- },
- */
-
- /* TODO: Enable this test when crbug.com/28055 is fixed. This bug causes a
- newly created window not to be set as the current window, if
- Chrome was not the foreground window when the create call was made.
- function windowsOnFocusChanged() {
- chrome.windows.create({}, pass(function(window) {
- chrome.test.listenOnce(chrome.windows.onFocusChanged,
- function(windowId) {
- assertEq(windowEventsWindow.id, windowId);
- });
- chrome.windows.remove(window.id);
- }));
- } */
-]);