| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/gfx/rect.h" | 6 #include "base/gfx/rect.h" |
| 7 #include "base/json_reader.h" | 7 #include "base/json_reader.h" |
| 8 #include "base/json_writer.h" | 8 #include "base/json_writer.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/automation/extension_automation_constants.h" | 10 #include "chrome/browser/automation/extension_automation_constants.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 EXPECT_TRUE(tab_dict.SetInteger( | 241 EXPECT_TRUE(tab_dict.SetInteger( |
| 242 extension_tabs_module_constants::kWindowIdKey, 1)); | 242 extension_tabs_module_constants::kWindowIdKey, 1)); |
| 243 EXPECT_TRUE(tab_dict.SetBoolean( | 243 EXPECT_TRUE(tab_dict.SetBoolean( |
| 244 extension_tabs_module_constants::kSelectedKey, true)); | 244 extension_tabs_module_constants::kSelectedKey, true)); |
| 245 EXPECT_TRUE(tab_dict.SetString( | 245 EXPECT_TRUE(tab_dict.SetString( |
| 246 extension_tabs_module_constants::kUrlKey, "http://www.google.com")); | 246 extension_tabs_module_constants::kUrlKey, "http://www.google.com")); |
| 247 | 247 |
| 248 std::string tab_json; | 248 std::string tab_json; |
| 249 JSONWriter::Write(&tab_dict, false, &tab_json); | 249 JSONWriter::Write(&tab_dict, false, &tab_json); |
| 250 | 250 |
| 251 EXPECT_TRUE(response_dict.SetString(keys::kAutomationResponseKey, tab_json
)); | 251 EXPECT_TRUE(response_dict.SetString(keys::kAutomationResponseKey, |
| 252 tab_json)); |
| 252 | 253 |
| 253 std::string response_json; | 254 std::string response_json; |
| 254 JSONWriter::Write(&response_dict, false, &response_json); | 255 JSONWriter::Write(&response_dict, false, &response_json); |
| 255 | 256 |
| 256 tab_->HandleMessageFromExternalHost( | 257 tab_->HandleMessageFromExternalHost( |
| 257 response_json, | 258 response_json, |
| 258 keys::kAutomationOrigin, | 259 keys::kAutomationOrigin, |
| 259 keys::kAutomationResponseTarget); | 260 keys::kAutomationResponseTarget); |
| 260 } else if (messages_received_ == 2) { | 261 } else if (messages_received_ == 2) { |
| 261 EXPECT_EQ(function_name, "tabs.remove"); | 262 EXPECT_EQ(function_name, "tabs.remove"); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 protected: | 329 protected: |
| 329 // Process a message received from the test extension. | 330 // Process a message received from the test extension. |
| 330 virtual void HandleMessageFromChrome(); | 331 virtual void HandleMessageFromChrome(); |
| 331 | 332 |
| 332 // Fire an event of the given name to the test extension. | 333 // Fire an event of the given name to the test extension. |
| 333 void FireEvent(const char* event_name); | 334 void FireEvent(const char* event_name); |
| 334 }; | 335 }; |
| 335 | 336 |
| 336 const char* BrowserEventAutomationProxy::events_[] = { | 337 const char* BrowserEventAutomationProxy::events_[] = { |
| 337 // Window events. | 338 // Window events. |
| 338 "[\"windows.onCreated\", \"[42]\"]", | 339 "[\"windows.onCreated\", \"[{'id':42}]\"]", |
| 339 | 340 |
| 340 "[\"windows.onRemoved\", \"[42]\"]", | 341 "[\"windows.onRemoved\", \"[42]\"]", |
| 341 | 342 |
| 342 "[\"windows.onFocusChanged\", \"[42]\"]", | 343 "[\"windows.onFocusChanged\", \"[42]\"]", |
| 343 | 344 |
| 344 // Tab events. | 345 // Tab events. |
| 345 "[\"tabs.onCreated\", \"[{'id\':42,'index':1,'windowId':1," | 346 "[\"tabs.onCreated\", \"[{'id\':42,'index':1,'windowId':1," |
| 346 "'selected':true,'url':'http://www.google.com'}]\"]", | 347 "'selected':true,'url':'http://www.google.com'}]\"]", |
| 347 | 348 |
| 348 "[\"tabs.onUpdated\", \"[42, {'status': 'complete'," | 349 "[\"tabs.onUpdated\", \"[42, {'status': 'complete'," |
| 349 "'url':'http://www.google.com'}]\"]", | 350 "'url':'http://www.google.com'}]\"]", |
| 350 | 351 |
| 351 "[\"tabs.onMoved\", \"[42, {'windowId':1,'fromIndex':1,'toIndex':2}]\"]", | 352 "[\"tabs.onMoved\", \"[42, {'windowId':1,'fromIndex':1,'toIndex':2}]\"]", |
| 352 | 353 |
| 353 "[\"tabs.onSelectionChanged\", \"[42, {'windowId':1}]\"]", | 354 "[\"tabs.onSelectionChanged\", \"[42, {'windowId':1}]\"]", |
| 354 | 355 |
| 355 "[\"tabs.onAttached\", \"[42, {'newWindowId':1,'newPosition':1}]\"]", | 356 "[\"tabs.onAttached\", \"[42, {'newWindowId':1,'newPosition':1}]\"]", |
| 356 | 357 |
| 357 "[\"tabs.onDetached\", \"[43, {'oldWindowId':1,'oldPosition':1}]\"]", | 358 "[\"tabs.onDetached\", \"[43, {'oldWindowId':1,'oldPosition':1}]\"]", |
| 358 | 359 |
| 359 "[\"tabs.onRemoved\", \"[43]\"]", | 360 "[\"tabs.onRemoved\", \"[43]\"]", |
| 360 | 361 |
| 361 // Bookmark events. | 362 // Bookmark events. |
| 362 "[\"bookmarks.onAdded\", \"['42', {'id':'42','title':'foo',}]\"]", | 363 "[\"bookmarks.onCreated\", \"['42', {'id':'42','title':'foo',}]\"]", |
| 363 | 364 |
| 364 "[\"bookmarks.onRemoved\", \"['42', {'parentId':'2','index':1}]\"]", | 365 "[\"bookmarks.onRemoved\", \"['42', {'parentId':'2','index':1}]\"]", |
| 365 | 366 |
| 366 "[\"bookmarks.onChanged\", \"['42', {'title':'foo'}]\"]", | 367 "[\"bookmarks.onChanged\", \"['42', {'title':'foo'}]\"]", |
| 367 | 368 |
| 368 "[\"bookmarks.onMoved\", \"['42', {'parentId':'2','index':1," | 369 "[\"bookmarks.onMoved\", \"['42', {'parentId':'2','index':1," |
| 369 "'oldParentId':'3','oldIndex':2}]\"]", | 370 "'oldParentId':'3','oldIndex':2}]\"]", |
| 370 | 371 |
| 371 "[\"bookmarks.onChildrenReordered\", \"['32', ['1', '2', '3']]\"]" | 372 "[\"bookmarks.onChildrenReordered\", \"['32', " |
| 373 "{'childIds':['1', '2', '3']}]\"]" |
| 372 }; | 374 }; |
| 373 | 375 |
| 374 void BrowserEventAutomationProxy::HandleMessageFromChrome() { | 376 void BrowserEventAutomationProxy::HandleMessageFromChrome() { |
| 375 namespace keys = extension_automation_constants; | 377 namespace keys = extension_automation_constants; |
| 376 ASSERT_TRUE(tab_ != NULL); | 378 ASSERT_TRUE(tab_ != NULL); |
| 377 | 379 |
| 378 std::string message(message()); | 380 std::string message(message()); |
| 379 std::string origin(origin()); | 381 std::string origin(origin()); |
| 380 std::string target(target()); | 382 std::string target(target()); |
| 381 | 383 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 proxy->event_count_.size()); | 497 proxy->event_count_.size()); |
| 496 for (std::map<std::string, int>::iterator i = proxy->event_count_.begin(); | 498 for (std::map<std::string, int>::iterator i = proxy->event_count_.begin(); |
| 497 i != proxy->event_count_.end(); ++i) { | 499 i != proxy->event_count_.end(); ++i) { |
| 498 const std::pair<std::string, int>& value = *i; | 500 const std::pair<std::string, int>& value = *i; |
| 499 ASSERT_EQ(1, value.second); | 501 ASSERT_EQ(1, value.second); |
| 500 } | 502 } |
| 501 } | 503 } |
| 502 #endif // defined(OS_WIN) | 504 #endif // defined(OS_WIN) |
| 503 | 505 |
| 504 } // namespace | 506 } // namespace |
| OLD | NEW |