OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/common/chrome_paths.h" | 8 #include "chrome/common/chrome_paths.h" |
9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
10 #include "chrome/renderer/extensions/extension_process_bindings.h" | 10 #include "chrome/renderer/extensions/extension_process_bindings.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 ExpectJsPass("chrome.windows.getAll(true, function(){})", | 165 ExpectJsPass("chrome.windows.getAll(true, function(){})", |
166 "GetAllWindows", "true"); | 166 "GetAllWindows", "true"); |
167 | 167 |
168 ExpectJsPass("chrome.windows.getAll(null, function(){})", | 168 ExpectJsPass("chrome.windows.getAll(null, function(){})", |
169 "GetAllWindows", "null"); | 169 "GetAllWindows", "null"); |
170 | 170 |
171 ExpectJsPass("chrome.windows.getAll(undefined, function(){})", | 171 ExpectJsPass("chrome.windows.getAll(undefined, function(){})", |
172 "GetAllWindows", "null"); | 172 "GetAllWindows", "null"); |
173 } | 173 } |
174 | 174 |
| 175 TEST_F(ExtensionAPIClientTest, CreateWindow) { |
| 176 ExpectJsFail("chrome.windows.create({url: 1}, function(){});", |
| 177 "Uncaught Error: Invalid value for argument 0. Property " |
| 178 "'url': Expected 'string' but got 'integer'."); |
| 179 ExpectJsFail("chrome.windows.create({left: 'foo'}, function(){});", |
| 180 "Uncaught Error: Invalid value for argument 0. Property " |
| 181 "'left': Expected 'integer' but got 'string'."); |
| 182 ExpectJsFail("chrome.windows.create({top: 'foo'}, function(){});", |
| 183 "Uncaught Error: Invalid value for argument 0. Property " |
| 184 "'top': Expected 'integer' but got 'string'."); |
| 185 ExpectJsFail("chrome.windows.create({width: 'foo'}, function(){});", |
| 186 "Uncaught Error: Invalid value for argument 0. Property " |
| 187 "'width': Expected 'integer' but got 'string'."); |
| 188 ExpectJsFail("chrome.windows.create({height: 'foo'}, function(){});", |
| 189 "Uncaught Error: Invalid value for argument 0. Property " |
| 190 "'height': Expected 'integer' but got 'string'."); |
| 191 ExpectJsFail("chrome.windows.create({foo: 42}, function(){});", |
| 192 "Uncaught Error: Invalid value for argument 0. Property " |
| 193 "'foo': Unexpected property."); |
| 194 |
| 195 ExpectJsPass("chrome.windows.create({" |
| 196 " url:'http://www.google.com/'," |
| 197 " left:0," |
| 198 " top: 10," |
| 199 " width:100," |
| 200 " height:200" |
| 201 "})", |
| 202 "CreateWindow", |
| 203 "{\"url\":\"http://www.google.com/\"," |
| 204 "\"left\":0," |
| 205 "\"top\":10," |
| 206 "\"width\":100," |
| 207 "\"height\":200}"); |
| 208 } |
| 209 |
| 210 TEST_F(ExtensionAPIClientTest, UpdateWindow) { |
| 211 ExpectJsFail("chrome.windows.update(null);", |
| 212 "Uncaught Error: Parameter 0 is required."); |
| 213 ExpectJsFail("chrome.windows.update(42, {left: 'foo'});", |
| 214 "Uncaught Error: Invalid value for argument 1. Property " |
| 215 "'left': Expected 'integer' but got 'string'."); |
| 216 ExpectJsFail("chrome.windows.update(42, {top: 'foo'});", |
| 217 "Uncaught Error: Invalid value for argument 1. Property " |
| 218 "'top': Expected 'integer' but got 'string'."); |
| 219 ExpectJsFail("chrome.windows.update(42, {height: false});", |
| 220 "Uncaught Error: Invalid value for argument 1. Property " |
| 221 "'height': Expected 'integer' but got 'boolean'."); |
| 222 ExpectJsFail("chrome.windows.update(42, {width: false});", |
| 223 "Uncaught Error: Invalid value for argument 1. Property " |
| 224 "'width': Expected 'integer' but got 'boolean'."); |
| 225 ExpectJsFail("chrome.windows.update(42, {foo: false});", |
| 226 "Uncaught Error: Invalid value for argument 1. Property " |
| 227 "'foo': Unexpected property."); |
| 228 |
| 229 ExpectJsPass("chrome.windows.update(42, {" |
| 230 " width:100," |
| 231 " height:200" |
| 232 "})", |
| 233 "UpdateWindow", |
| 234 "[42," |
| 235 "{\"width\":100," |
| 236 "\"height\":200}]"); |
| 237 } |
| 238 |
| 239 TEST_F(ExtensionAPIClientTest, RemoveWindow) { |
| 240 ExpectJsFail("chrome.windows.remove(32, function(){}, 20);", |
| 241 "Uncaught Error: Too many arguments."); |
| 242 |
| 243 ExpectJsFail("chrome.windows.remove('abc', function(){});", |
| 244 "Uncaught Error: Invalid value for argument 0. " |
| 245 "Expected 'integer' but got 'string'."); |
| 246 |
| 247 ExpectJsFail("chrome.windows.remove(1, 1);", |
| 248 "Uncaught Error: Invalid value for argument 1. " |
| 249 "Expected 'function' but got 'integer'."); |
| 250 |
| 251 ExpectJsPass("chrome.windows.remove(2, function(){})", |
| 252 "RemoveWindow", "2"); |
| 253 |
| 254 ExpectJsPass("chrome.windows.remove(2)", |
| 255 "RemoveWindow", "2"); |
| 256 } |
| 257 |
175 // Tab API tests | 258 // Tab API tests |
176 | 259 |
177 TEST_F(ExtensionAPIClientTest, GetTab) { | 260 TEST_F(ExtensionAPIClientTest, GetTab) { |
178 ExpectJsFail("chrome.tabs.get(32, function(){}, 20);", | 261 ExpectJsFail("chrome.tabs.get(32, function(){}, 20);", |
179 "Uncaught Error: Too many arguments."); | 262 "Uncaught Error: Too many arguments."); |
180 | 263 |
181 ExpectJsFail("chrome.tabs.get(32);", | 264 ExpectJsFail("chrome.tabs.get(32);", |
182 "Uncaught Error: Parameter 1 is required."); | 265 "Uncaught Error: Parameter 1 is required."); |
183 | 266 |
184 ExpectJsFail("chrome.tabs.get('abc', function(){});", | 267 ExpectJsFail("chrome.tabs.get('abc', function(){});", |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 "SetBookmarkTitle", | 471 "SetBookmarkTitle", |
389 "{\"id\":42,\"title\":\"x\"}"); | 472 "{\"id\":42,\"title\":\"x\"}"); |
390 } | 473 } |
391 | 474 |
392 TEST_F(ExtensionAPIClientTest, EnablePageAction) { | 475 TEST_F(ExtensionAPIClientTest, EnablePageAction) { |
393 ExpectJsPass("chrome.pageActions.enableForTab(" | 476 ExpectJsPass("chrome.pageActions.enableForTab(" |
394 "\"dummy\", {tabId: 0, url: \"http://foo/\"});", | 477 "\"dummy\", {tabId: 0, url: \"http://foo/\"});", |
395 "EnablePageAction", | 478 "EnablePageAction", |
396 "[\"dummy\",{\"tabId\":0,\"url\":\"http://foo/\"}]"); | 479 "[\"dummy\",{\"tabId\":0,\"url\":\"http://foo/\"}]"); |
397 } | 480 } |
OLD | NEW |