summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-05 03:05:00 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-05 03:05:00 +0000
commite515f5de833d9298682570fd2f70abb16d032912 (patch)
tree05b4a10956097b7e173ebbc8153c5b557180bac8 /chrome/renderer
parent126f4120902008da93759d7256c87e1e6d3ae70b (diff)
downloadchromium_src-e515f5de833d9298682570fd2f70abb16d032912.zip
chromium_src-e515f5de833d9298682570fd2f70abb16d032912.tar.gz
chromium_src-e515f5de833d9298682570fd2f70abb16d032912.tar.bz2
implemented API style/convention changes, including:
-tabs.update() -tabs.move() -tabs.remove() -tabs.update() -tabs.create() -tabs.get() -all tab events, except onUpdated implemented -tabs.getSelected() -tabs.getAllInWindow() -windows.getCurrent() -windows.getFocused() -windows.getAll(populate) -windows.onFocusedChanged() -ExtensionBrowserEventRouter now uses BrowserList::Observer Review URL: http://codereview.chromium.org/100345 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15271 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rwxr-xr-xchrome/renderer/extensions/extension_api_client_unittest.cc198
-rwxr-xr-xchrome/renderer/renderer_resources.grd2
-rw-r--r--chrome/renderer/resources/extension_process_bindings.js148
3 files changed, 262 insertions, 86 deletions
diff --git a/chrome/renderer/extensions/extension_api_client_unittest.cc b/chrome/renderer/extensions/extension_api_client_unittest.cc
index 172263a..6233dfb 100755
--- a/chrome/renderer/extensions/extension_api_client_unittest.cc
+++ b/chrome/renderer/extensions/extension_api_client_unittest.cc
@@ -75,7 +75,7 @@ TEST_F(ExtensionAPIClientTest, CallbackDispatching) {
" 'incorrect result');"
" console.log('pass')"
"}"
- "chromium.tabs.createTab({}, callback);"
+ "chromium.tabs.create({}, callback);"
);
EXPECT_EQ("", GetConsoleMessage());
@@ -102,72 +102,210 @@ TEST_F(ExtensionAPIClientTest, CallbackDispatching) {
// extension functions. We test both error and success conditions, but do not
// test errors exhaustively as json schema code is well tested by itself.
-TEST_F(ExtensionAPIClientTest, GetTabsForWindow) {
- ExpectJsFail("chromium.tabs.getTabsForWindow(42, function(){});",
+// Window API tests
+
+TEST_F(ExtensionAPIClientTest, GetWindow) {
+ ExpectJsFail("chromium.windows.get(32, function(){}, 20);",
"Uncaught Error: Too many arguments.");
- ExpectJsPass("chromium.tabs.getTabsForWindow(function(){})",
- "GetTabsForWindow", "null");
+ ExpectJsFail("chromium.windows.get(32);",
+ "Uncaught Error: Parameter 1 is required.");
+
+ ExpectJsFail("chromium.windows.get('abc', function(){});",
+ "Uncaught Error: Invalid value for argument 0. "
+ "Expected 'integer' but got 'string'.");
+
+ ExpectJsFail("chromium.windows.get(1, 1);",
+ "Uncaught Error: Invalid value for argument 1. "
+ "Expected 'function' but got 'integer'.");
+
+ ExpectJsPass("chromium.windows.get(2, function(){})",
+ "GetWindow", "2");
}
-TEST_F(ExtensionAPIClientTest, GetTab) {
- ExpectJsFail("chromium.tabs.getTab(null, function(){});",
+TEST_F(ExtensionAPIClientTest, GetCurentWindow) {
+ ExpectJsFail("chromium.windows.getCurrent(function(){}, 20);",
+ "Uncaught Error: Too many arguments.");
+
+ ExpectJsFail("chromium.windows.getCurrent();",
+ "Uncaught Error: Parameter 0 is required.");
+
+ ExpectJsFail("chromium.windows.getCurrent('abc');",
+ "Uncaught Error: Invalid value for argument 0. "
+ "Expected 'function' but got 'string'.");
+
+ ExpectJsPass("chromium.windows.getCurrent(function(){})",
+ "GetCurrentWindow", "null");
+}
+
+TEST_F(ExtensionAPIClientTest, GetFocusedWindow) {
+ ExpectJsFail("chromium.windows.getFocused(function(){}, 20);",
+ "Uncaught Error: Too many arguments.");
+
+ ExpectJsFail("chromium.windows.getFocused();",
"Uncaught Error: Parameter 0 is required.");
- ExpectJsPass("chromium.tabs.getTab(42)", "GetTab", "42");
+ ExpectJsFail("chromium.windows.getFocused('abc');",
+ "Uncaught Error: Invalid value for argument 0. "
+ "Expected 'function' but got 'string'.");
+
+ ExpectJsPass("chromium.windows.getFocused(function(){})",
+ "GetFocusedWindow", "null");
+}
+
+TEST_F(ExtensionAPIClientTest, GetAllWindows) {
+ ExpectJsFail("chromium.windows.getAll(true, function(){}, 20);",
+ "Uncaught Error: Too many arguments.");
+
+ ExpectJsFail("chromium.windows.getAll(1, function(){});",
+ "Uncaught Error: Invalid value for argument 0. "
+ "Expected 'boolean' but got 'integer'.");
+
+ ExpectJsPass("chromium.windows.getAll(true, function(){})",
+ "GetAllWindows", "true");
+
+ ExpectJsPass("chromium.windows.getAll(null, function(){})",
+ "GetAllWindows", "null");
+
+ ExpectJsPass("chromium.windows.getAll(undefined, function(){})",
+ "GetAllWindows", "null");
+}
+
+// Tab API tests
+
+TEST_F(ExtensionAPIClientTest, GetTab) {
+ ExpectJsFail("chromium.tabs.get(32, function(){}, 20);",
+ "Uncaught Error: Too many arguments.");
+
+ ExpectJsFail("chromium.tabs.get(32);",
+ "Uncaught Error: Parameter 1 is required.");
+
+ ExpectJsFail("chromium.tabs.get('abc', function(){});",
+ "Uncaught Error: Invalid value for argument 0. "
+ "Expected 'integer' but got 'string'.");
+
+ ExpectJsFail("chromium.tabs.get(1, 1);",
+ "Uncaught Error: Invalid value for argument 1. "
+ "Expected 'function' but got 'integer'.");
+
+ ExpectJsPass("chromium.tabs.get(2, function(){})",
+ "GetTab", "2");
+}
+
+TEST_F(ExtensionAPIClientTest, GetSelectedTab) {
+ ExpectJsFail("chromium.tabs.getSelected(32, function(){}, 20);",
+ "Uncaught Error: Too many arguments.");
+
+ ExpectJsFail("chromium.tabs.getSelected(32);",
+ "Uncaught Error: Parameter 1 is required.");
+
+ ExpectJsFail("chromium.tabs.getSelected('abc', function(){});",
+ "Uncaught Error: Invalid value for argument 0. "
+ "Expected 'integer' but got 'string'.");
+
+ ExpectJsFail("chromium.tabs.getSelected(1, 1);",
+ "Uncaught Error: Invalid value for argument 1. "
+ "Expected 'function' but got 'integer'.");
+
+ ExpectJsPass("chromium.tabs.getSelected(2, function(){})",
+ "GetSelectedTab", "2");
+
+ ExpectJsPass("chromium.tabs.getSelected(null, function(){})",
+ "GetSelectedTab", "null");
+}
+
+
+TEST_F(ExtensionAPIClientTest, GetAllTabsInWindow) {
+ ExpectJsFail("chromium.tabs.getAllInWindow(42, function(){}, 'asd');",
+ "Uncaught Error: Too many arguments.");
+
+ ExpectJsFail("chromium.tabs.getAllInWindow(32);",
+ "Uncaught Error: Parameter 1 is required.");
+
+ ExpectJsFail("chromium.tabs.getAllInWindow(1, 1);",
+ "Uncaught Error: Invalid value for argument 1. "
+ "Expected 'function' but got 'integer'.");
+
+ ExpectJsFail("chromium.tabs.getAllInWindow('asd', function(){});",
+ "Uncaught Error: Invalid value for argument 0. "
+ "Expected 'integer' but got 'string'.");
+
+ ExpectJsPass("chromium.tabs.getAllInWindow(32, function(){})",
+ "GetAllTabsInWindow", "32");
+
+ ExpectJsPass("chromium.tabs.getAllInWindow(undefined, function(){})",
+ "GetAllTabsInWindow", "null");
}
TEST_F(ExtensionAPIClientTest, CreateTab) {
- ExpectJsFail("chromium.tabs.createTab({windowId: 'foo'}, function(){});",
+ ExpectJsFail("chromium.tabs.create({windowId: 'foo'}, function(){});",
"Uncaught Error: Invalid value for argument 0. Property "
"'windowId': Expected 'integer' but got 'string'.");
- ExpectJsFail("chromium.tabs.createTab({url: 42}, function(){});",
+ ExpectJsFail("chromium.tabs.create({url: 42}, function(){});",
"Uncaught Error: Invalid value for argument 0. Property "
"'url': Expected 'string' but got 'integer'.");
- ExpectJsFail("chromium.tabs.createTab({foo: 42}, function(){});",
+ ExpectJsFail("chromium.tabs.create({foo: 42}, function(){});",
"Uncaught Error: Invalid value for argument 0. Property "
"'foo': Unexpected property.");
- ExpectJsPass("chromium.tabs.createTab({"
+ ExpectJsPass("chromium.tabs.create({"
" url:'http://www.google.com/',"
" selected:true,"
+ " index: 2,"
" windowId:4"
"})",
"CreateTab",
"{\"url\":\"http://www.google.com/\","
"\"selected\":true,"
+ "\"index\":2,"
"\"windowId\":4}");
}
TEST_F(ExtensionAPIClientTest, UpdateTab) {
- ExpectJsFail("chromium.tabs.updateTab({id: null});",
- "Uncaught Error: Invalid value for argument 0. Property "
- "'id': Property is required.");
- ExpectJsFail("chromium.tabs.updateTab({id: 42, windowId: 'foo'});",
- "Uncaught Error: Invalid value for argument 0. Property "
- "'windowId': Expected 'integer' but got 'string'.");
- ExpectJsFail("chromium.tabs.updateTab({id: 42, url: 42});",
- "Uncaught Error: Invalid value for argument 0. Property "
+ ExpectJsFail("chromium.tabs.update(null);",
+ "Uncaught Error: Parameter 0 is required.");
+ ExpectJsFail("chromium.tabs.update(42, {selected: 'foo'});",
+ "Uncaught Error: Invalid value for argument 1. Property "
+ "'selected': Expected 'boolean' but got 'string'.");
+ ExpectJsFail("chromium.tabs.update(42, {url: 42});",
+ "Uncaught Error: Invalid value for argument 1. Property "
"'url': Expected 'string' but got 'integer'.");
- ExpectJsPass("chromium.tabs.updateTab({"
- " id:42,"
+ ExpectJsPass("chromium.tabs.update(42, {"
" url:'http://www.google.com/',"
- " selected:true,"
- " windowId:4"
+ " selected:true"
"})",
"UpdateTab",
- "{\"id\":42,"
- "\"url\":\"http://www.google.com/\","
- "\"selected\":true,"
- "\"windowId\":4}");
+ "[42,"
+ "{\"url\":\"http://www.google.com/\","
+ "\"selected\":true}]");
+}
+
+TEST_F(ExtensionAPIClientTest, MoveTab) {
+ ExpectJsFail("chromium.tabs.move(null);",
+ "Uncaught Error: Parameter 0 is required.");
+ ExpectJsFail("chromium.tabs.move(42, {index: 'foo'});",
+ "Uncaught Error: Invalid value for argument 1. Property "
+ "'index': Expected 'integer' but got 'string'.");
+ ExpectJsFail("chromium.tabs.move(42, {index: 3, windowId: 'foo'});",
+ "Uncaught Error: Invalid value for argument 1. Property "
+ "'windowId': Expected 'integer' but got 'string'.");
+
+ ExpectJsPass("chromium.tabs.move(42, {"
+ " index:3,"
+ " windowId:21"
+ "})",
+ "MoveTab",
+ "[42,"
+ "{\"index\":3,"
+ "\"windowId\":21}]");
}
TEST_F(ExtensionAPIClientTest, RemoveTab) {
- ExpectJsFail("chromium.tabs.removeTab('foobar', function(){});",
+ ExpectJsFail("chromium.tabs.remove('foobar', function(){});",
"Uncaught Error: Too many arguments.");
- ExpectJsPass("chromium.tabs.removeTab(21)", "RemoveTab", "21");
+ ExpectJsPass("chromium.tabs.remove(21)", "RemoveTab", "21");
}
// Bookmark API tests
diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd
index cda253b..c59e98c 100755
--- a/chrome/renderer/renderer_resources.grd
+++ b/chrome/renderer/renderer_resources.grd
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This comment is only here because changes to resources are not picked up
-without changes to the corresponding grd file. -->
+without changes to the corresponding grd file. -->
<grit latest_public_release="0" current_release="1">
<outputs>
<output filename="grit/renderer_resources.h" type="rc_header">
diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js
index 00bb0fa..d1907d8 100644
--- a/chrome/renderer/resources/extension_process_bindings.js
+++ b/chrome/renderer/resources/extension_process_bindings.js
@@ -10,11 +10,15 @@
var chromium;
(function() {
native function GetNextCallbackId();
+ native function GetWindow();
+ native function GetCurrentWindow();
+ native function GetFocusedWindow();
native function CreateWindow();
native function RemoveWindow();
- native function GetWindows();
- native function GetTabsForWindow();
+ native function GetAllWindows();
native function GetTab();
+ native function GetSelectedTab();
+ native function GetAllTabsInWindow();
native function CreateTab();
native function UpdateTab();
native function MoveTab();
@@ -95,24 +99,42 @@ var chromium;
// Windows.
chromium.windows = {};
- chromium.windows.getWindows = function(windowQuery, callback) {
+ chromium.windows.get = function(windowId, callback) {
validate(arguments, arguments.callee.params);
- sendRequest(GetWindows, windowQuery, callback);
+ sendRequest(GetWindow, windowId, callback);
};
- chromium.windows.getWindows.params = [
- {
- type: "object",
- properties: {
- ids: {
- type: "array",
- items: chromium.types.pInt,
- minItems: 1
- }
- },
- optional: true
- },
- chromium.types.optFun
+ chromium.windows.get.params = [
+ chromium.types.pInt,
+ chromium.types.fun
+ ];
+
+ chromium.windows.getCurrent = function(callback) {
+ validate(arguments, arguments.callee.params);
+ sendRequest(GetCurrentWindow, null, callback);
+ };
+
+ chromium.windows.getCurrent.params = [
+ chromium.types.fun
+ ];
+
+ chromium.windows.getFocused = function(callback) {
+ validate(arguments, arguments.callee.params);
+ sendRequest(GetFocusedWindow, null, callback);
+ };
+
+ chromium.windows.getFocused.params = [
+ chromium.types.fun
+ ];
+
+ chromium.windows.getAll = function(populate, callback) {
+ validate(arguments, arguments.callee.params);
+ sendRequest(GetAllWindows, populate, callback);
+ };
+
+ chromium.windows.getAll.params = [
+ chromium.types.optBool,
+ chromium.types.fun
];
chromium.windows.createWindow = function(createData, callback) {
@@ -146,49 +168,64 @@ var chromium;
// sends (windowId).
// *WILL* be followed by tab-attached AND then tab-selection-changed.
- chromium.windows.onWindowCreated = new chromium.Event("window-created");
+ chromium.windows.onCreated = new chromium.Event("window-created");
// sends (windowId).
// *WILL* be preceded by sequences of tab-removed AND then
// tab-selection-changed -- one for each tab that was contained in the window
// that closed
- chromium.windows.onWindowRemoved = new chromium.Event("window-removed");
+ chromium.windows.onRemoved = new chromium.Event("window-removed");
+
+ // sends (windowId).
+ chromium.windows.onFocusChanged =
+ new chromium.Event("window-focus-changed");
//----------------------------------------------------------------------------
// Tabs
chromium.tabs = {};
- // TODO(aa): This should eventually take an optional windowId param.
- chromium.tabs.getTabsForWindow = function(callback) {
+ chromium.tabs.get = function(tabId, callback) {
validate(arguments, arguments.callee.params);
- sendRequest(GetTabsForWindow, null, callback);
+ sendRequest(GetTab, tabId, callback);
};
- chromium.tabs.getTabsForWindow.params = [
- chromium.types.optFun
+ chromium.tabs.get.params = [
+ chromium.types.pInt,
+ chromium.types.fun
+ ];
+
+ chromium.tabs.getSelected = function(windowId, callback) {
+ validate(arguments, arguments.callee.params);
+ sendRequest(GetSelectedTab, windowId, callback);
+ };
+
+ chromium.tabs.getSelected.params = [
+ chromium.types.optPInt,
+ chromium.types.fun
];
- chromium.tabs.getTab = function(tabId, callback) {
+ chromium.tabs.getAllInWindow = function(windowId, callback) {
validate(arguments, arguments.callee.params);
- sendRequest(GetTab, tabId, callback);
+ sendRequest(GetAllTabsInWindow, windowId, callback);
};
- chromium.tabs.getTab.params = [
- chromium.types.pInt,
- chromium.types.optFun
+ chromium.tabs.getAllInWindow.params = [
+ chromium.types.optPInt,
+ chromium.types.fun
];
- chromium.tabs.createTab = function(tab, callback) {
+ chromium.tabs.create = function(tab, callback) {
validate(arguments, arguments.callee.params);
sendRequest(CreateTab, tab, callback);
};
- chromium.tabs.createTab.params = [
+ chromium.tabs.create.params = [
{
type: "object",
properties: {
windowId: chromium.types.optPInt,
+ index: chromium.types.optPInt,
url: chromium.types.optStr,
selected: chromium.types.optBool
}
@@ -196,73 +233,74 @@ var chromium;
chromium.types.optFun
];
- chromium.tabs.updateTab = function(tab) {
+ chromium.tabs.update = function(tabId, updates, callback) {
validate(arguments, arguments.callee.params);
- sendRequest(UpdateTab, tab);
+ sendRequest(UpdateTab, [tabId, updates], callback);
};
- chromium.tabs.updateTab.params = [
+ chromium.tabs.update.params = [
+ chromium.types.pInt,
{
type: "object",
properties: {
- id: chromium.types.pInt,
- windowId: chromium.types.optPInt,
url: chromium.types.optStr,
selected: chromium.types.optBool
}
- }
+ },
+ chromium.types.optFun
];
- chromium.tabs.moveTab = function(tab) {
+ chromium.tabs.move = function(tabId, moveProps, callback) {
validate(arguments, arguments.callee.params);
- sendRequest(MoveTab, tab);
+ sendRequest(MoveTab, [tabId, moveProps], callback);
};
- chromium.tabs.moveTab.params = [
+ chromium.tabs.move.params = [
+ chromium.types.pInt,
{
type: "object",
properties: {
- id: chromium.types.pInt,
windowId: chromium.types.optPInt,
index: chromium.types.pInt
}
- }
+ },
+ chromium.types.optFun
];
- chromium.tabs.removeTab = function(tabId) {
+ chromium.tabs.remove = function(tabId) {
validate(arguments, arguments.callee.params);
sendRequest(RemoveTab, tabId);
};
- chromium.tabs.removeTab.params = [
+ chromium.tabs.remove.params = [
chromium.types.pInt
];
- // Sends ({tabId, windowId, index}).
+ // Sends ({Tab}).
// Will *NOT* be followed by tab-attached - it is implied.
// *MAY* be followed by tab-selection-changed.
- chromium.tabs.onTabCreated = new chromium.Event("tab-created");
+ chromium.tabs.onCreated = new chromium.Event("tab-created");
- // Wends ({tabId, windowId, fromIndex, toIndex}).
+ // Sends (tabId, {windowId, fromIndex, toIndex}).
// Tabs can only "move" within a window.
- chromium.tabs.onTabMoved = new chromium.Event("tab-moved");
+ chromium.tabs.onMoved = new chromium.Event("tab-moved");
- // Sends ({tabId, windowId, index}).
- chromium.tabs.onTabSelectionChanged =
+ // Sends (tabId, {windowId}).
+ chromium.tabs.onSelectionChanged =
new chromium.Event("tab-selection-changed");
- // Sends ({tabId, windowId, index}).
+ // Sends (tabId, {newWindowId, newPosition}).
// *MAY* be followed by tab-selection-changed.
- chromium.tabs.onTabAttached = new chromium.Event("tab-attached");
+ chromium.tabs.onAttached = new chromium.Event("tab-attached");
- // Sends ({tabId, windowId, index}).
+ // Sends (tabId, {oldWindowId, oldPosition}).
// *WILL* be followed by tab-selection-changed.
- chromium.tabs.onTabDetached = new chromium.Event("tab-detached");
+ chromium.tabs.onDetached = new chromium.Event("tab-detached");
// Sends (tabId).
// *WILL* be followed by tab-selection-changed.
// Will *NOT* be followed or preceded by tab-detached.
- chromium.tabs.onTabRemoved = new chromium.Event("tab-removed");
+ chromium.tabs.onRemoved = new chromium.Event("tab-removed");
//----------------------------------------------------------------------------