Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Side by Side Diff: chrome/browser/extensions/extension_uitest.cc

Issue 316016: Move the json-related files into a separate json directory. This hopefully al... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/json_reader.h"
8 #include "base/json_writer.h" 8 #include "base/json/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"
11 #include "chrome/browser/extensions/extension_tabs_module_constants.h" 11 #include "chrome/browser/extensions/extension_tabs_module_constants.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
14 #include "chrome/test/automation/automation_messages.h" 14 #include "chrome/test/automation/automation_messages.h"
15 #include "chrome/test/automation/automation_proxy_uitest.h" 15 #include "chrome/test/automation/automation_proxy_uitest.h"
16 #include "chrome/test/automation/tab_proxy.h" 16 #include "chrome/test/automation/tab_proxy.h"
17 #include "chrome/test/ui/ui_test.h" 17 #include "chrome/test/ui/ui_test.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 "chrome-extension://pmgpglkggjdpkpghhdmbdhababjpcohk/test.html")); 116 "chrome-extension://pmgpglkggjdpkpghhdmbdhababjpcohk/test.html"));
117 AutomationProxyForExternalTab* proxy = 117 AutomationProxyForExternalTab* proxy =
118 static_cast<AutomationProxyForExternalTab*>(automation()); 118 static_cast<AutomationProxyForExternalTab*>(automation());
119 ASSERT_GT(proxy->messages_received(), 0); 119 ASSERT_GT(proxy->messages_received(), 0);
120 120
121 // Using EXPECT_TRUE rather than EXPECT_EQ as the compiler (VC++) isn't 121 // Using EXPECT_TRUE rather than EXPECT_EQ as the compiler (VC++) isn't
122 // finding the right match for EqHelper. 122 // finding the right match for EqHelper.
123 EXPECT_TRUE(proxy->origin() == keys::kAutomationOrigin); 123 EXPECT_TRUE(proxy->origin() == keys::kAutomationOrigin);
124 EXPECT_TRUE(proxy->target() == keys::kAutomationRequestTarget); 124 EXPECT_TRUE(proxy->target() == keys::kAutomationRequestTarget);
125 125
126 scoped_ptr<Value> message_value(JSONReader::Read(proxy->message(), false)); 126 scoped_ptr<Value> message_value(base::JSONReader::Read(proxy->message(),
127 false));
127 ASSERT_TRUE(message_value->IsType(Value::TYPE_DICTIONARY)); 128 ASSERT_TRUE(message_value->IsType(Value::TYPE_DICTIONARY));
128 DictionaryValue* message_dict = 129 DictionaryValue* message_dict =
129 reinterpret_cast<DictionaryValue*>(message_value.get()); 130 reinterpret_cast<DictionaryValue*>(message_value.get());
130 std::string result; 131 std::string result;
131 ASSERT_TRUE(message_dict->GetString(keys::kAutomationNameKey, &result)); 132 ASSERT_TRUE(message_dict->GetString(keys::kAutomationNameKey, &result));
132 EXPECT_EQ(result, "tabs.remove"); 133 EXPECT_EQ(result, "tabs.remove");
133 134
134 result = ""; 135 result = "";
135 ASSERT_TRUE(message_dict->GetString(keys::kAutomationArgsKey, &result)); 136 ASSERT_TRUE(message_dict->GetString(keys::kAutomationArgsKey, &result));
136 EXPECT_NE(result, ""); 137 EXPECT_NE(result, "");
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 namespace keys = extension_automation_constants; 202 namespace keys = extension_automation_constants;
202 203
203 ASSERT_TRUE(tab_ != NULL); 204 ASSERT_TRUE(tab_ != NULL);
204 ASSERT_TRUE(messages_received_ == 1 || messages_received_ == 2); 205 ASSERT_TRUE(messages_received_ == 1 || messages_received_ == 2);
205 206
206 // Using EXPECT_TRUE rather than EXPECT_EQ as the compiler (VC++) isn't 207 // Using EXPECT_TRUE rather than EXPECT_EQ as the compiler (VC++) isn't
207 // finding the right match for EqHelper. 208 // finding the right match for EqHelper.
208 EXPECT_TRUE(origin_ == keys::kAutomationOrigin); 209 EXPECT_TRUE(origin_ == keys::kAutomationOrigin);
209 EXPECT_TRUE(target_ == keys::kAutomationRequestTarget); 210 EXPECT_TRUE(target_ == keys::kAutomationRequestTarget);
210 211
211 scoped_ptr<Value> message_value(JSONReader::Read(message_, false)); 212 scoped_ptr<Value> message_value(base::JSONReader::Read(message_, false));
212 ASSERT_TRUE(message_value->IsType(Value::TYPE_DICTIONARY)); 213 ASSERT_TRUE(message_value->IsType(Value::TYPE_DICTIONARY));
213 DictionaryValue* request_dict = 214 DictionaryValue* request_dict =
214 static_cast<DictionaryValue*>(message_value.get()); 215 static_cast<DictionaryValue*>(message_value.get());
215 std::string function_name; 216 std::string function_name;
216 ASSERT_TRUE(request_dict->GetString(keys::kAutomationNameKey, 217 ASSERT_TRUE(request_dict->GetString(keys::kAutomationNameKey,
217 &function_name)); 218 &function_name));
218 int request_id = -2; 219 int request_id = -2;
219 EXPECT_TRUE(request_dict->GetInteger(keys::kAutomationRequestIdKey, 220 EXPECT_TRUE(request_dict->GetInteger(keys::kAutomationRequestIdKey,
220 &request_id)); 221 &request_id));
221 bool has_callback = false; 222 bool has_callback = false;
(...skipping 14 matching lines...) Expand all
236 EXPECT_TRUE(tab_dict.SetInteger( 237 EXPECT_TRUE(tab_dict.SetInteger(
237 extension_tabs_module_constants::kIndexKey, 1)); 238 extension_tabs_module_constants::kIndexKey, 1));
238 EXPECT_TRUE(tab_dict.SetInteger( 239 EXPECT_TRUE(tab_dict.SetInteger(
239 extension_tabs_module_constants::kWindowIdKey, 1)); 240 extension_tabs_module_constants::kWindowIdKey, 1));
240 EXPECT_TRUE(tab_dict.SetBoolean( 241 EXPECT_TRUE(tab_dict.SetBoolean(
241 extension_tabs_module_constants::kSelectedKey, true)); 242 extension_tabs_module_constants::kSelectedKey, true));
242 EXPECT_TRUE(tab_dict.SetString( 243 EXPECT_TRUE(tab_dict.SetString(
243 extension_tabs_module_constants::kUrlKey, "http://www.google.com")); 244 extension_tabs_module_constants::kUrlKey, "http://www.google.com"));
244 245
245 std::string tab_json; 246 std::string tab_json;
246 JSONWriter::Write(&tab_dict, false, &tab_json); 247 base::JSONWriter::Write(&tab_dict, false, &tab_json);
247 248
248 EXPECT_TRUE(response_dict.SetString(keys::kAutomationResponseKey, 249 EXPECT_TRUE(response_dict.SetString(keys::kAutomationResponseKey,
249 tab_json)); 250 tab_json));
250 251
251 std::string response_json; 252 std::string response_json;
252 JSONWriter::Write(&response_dict, false, &response_json); 253 base::JSONWriter::Write(&response_dict, false, &response_json);
253 254
254 tab_->HandleMessageFromExternalHost( 255 tab_->HandleMessageFromExternalHost(
255 response_json, 256 response_json,
256 keys::kAutomationOrigin, 257 keys::kAutomationOrigin,
257 keys::kAutomationResponseTarget); 258 keys::kAutomationResponseTarget);
258 } else if (messages_received_ == 2) { 259 } else if (messages_received_ == 2) {
259 EXPECT_EQ(function_name, "tabs.remove"); 260 EXPECT_EQ(function_name, "tabs.remove");
260 EXPECT_FALSE(has_callback); 261 EXPECT_FALSE(has_callback);
261 262
262 std::string args; 263 std::string args;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 std::string origin(origin()); 380 std::string origin(origin());
380 std::string target(target()); 381 std::string target(target());
381 382
382 ASSERT_TRUE(message.length() > 0); 383 ASSERT_TRUE(message.length() > 0);
383 ASSERT_STREQ(keys::kAutomationOrigin, origin.c_str()); 384 ASSERT_STREQ(keys::kAutomationOrigin, origin.c_str());
384 385
385 if (target == keys::kAutomationRequestTarget) { 386 if (target == keys::kAutomationRequestTarget) {
386 // This should be a request for the current window. We don't need to 387 // This should be a request for the current window. We don't need to
387 // respond, as this is used only as an indication that the extension 388 // respond, as this is used only as an indication that the extension
388 // page is now loaded. 389 // page is now loaded.
389 scoped_ptr<Value> message_value(JSONReader::Read(message, false)); 390 scoped_ptr<Value> message_value(base::JSONReader::Read(message, false));
390 ASSERT_TRUE(message_value->IsType(Value::TYPE_DICTIONARY)); 391 ASSERT_TRUE(message_value->IsType(Value::TYPE_DICTIONARY));
391 DictionaryValue* message_dict = 392 DictionaryValue* message_dict =
392 reinterpret_cast<DictionaryValue*>(message_value.get()); 393 reinterpret_cast<DictionaryValue*>(message_value.get());
393 394
394 std::string name; 395 std::string name;
395 ASSERT_TRUE(message_dict->GetString(keys::kAutomationNameKey, &name)); 396 ASSERT_TRUE(message_dict->GetString(keys::kAutomationNameKey, &name));
396 ASSERT_STREQ(name.c_str(), "windows.getCurrent"); 397 ASSERT_STREQ(name.c_str(), "windows.getCurrent");
397 398
398 // Send an OpenChannelToExtension message to chrome. Note: the JSON 399 // Send an OpenChannelToExtension message to chrome. Note: the JSON
399 // reader expects quoted property keys. See the comment in 400 // reader expects quoted property keys. See the comment in
(...skipping 11 matching lines...) Expand all
411 FireEvent(events_[i]); 412 FireEvent(events_[i]);
412 } 413 }
413 } else if (target == keys::kAutomationPortRequestTarget) { 414 } else if (target == keys::kAutomationPortRequestTarget) {
414 // This is the test extension calling us back. Make sure its telling 415 // This is the test extension calling us back. Make sure its telling
415 // us that it received an event. We do this by checking to see if the 416 // us that it received an event. We do this by checking to see if the
416 // message is a simple string of one of the event names that is fired. 417 // message is a simple string of one of the event names that is fired.
417 // 418 //
418 // There is a special message "ACK" which means that the extension 419 // There is a special message "ACK" which means that the extension
419 // received the port connection. This is not an event response and 420 // received the port connection. This is not an event response and
420 // should happen before all events. 421 // should happen before all events.
421 scoped_ptr<Value> message_value(JSONReader::Read(message, false)); 422 scoped_ptr<Value> message_value(base::JSONReader::Read(message, false));
422 ASSERT_TRUE(message_value->IsType(Value::TYPE_DICTIONARY)); 423 ASSERT_TRUE(message_value->IsType(Value::TYPE_DICTIONARY));
423 DictionaryValue* message_dict = 424 DictionaryValue* message_dict =
424 reinterpret_cast<DictionaryValue*>(message_value.get()); 425 reinterpret_cast<DictionaryValue*>(message_value.get());
425 426
426 std::string event_name; 427 std::string event_name;
427 ASSERT_TRUE(message_dict->GetString(L"data", &event_name)); 428 ASSERT_TRUE(message_dict->GetString(L"data", &event_name));
428 if (event_name == "\"ACK\"") { 429 if (event_name == "\"ACK\"") {
429 ASSERT_EQ(0, event_count_.size()); 430 ASSERT_EQ(0, event_count_.size());
430 } else { 431 } else {
431 ++event_count_[event_name]; 432 ++event_count_[event_name];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 proxy->event_count_.size()); 489 proxy->event_count_.size());
489 for (std::map<std::string, int>::iterator i = proxy->event_count_.begin(); 490 for (std::map<std::string, int>::iterator i = proxy->event_count_.begin();
490 i != proxy->event_count_.end(); ++i) { 491 i != proxy->event_count_.end(); ++i) {
491 const std::pair<std::string, int>& value = *i; 492 const std::pair<std::string, int>& value = *i;
492 ASSERT_EQ(1, value.second); 493 ASSERT_EQ(1, value.second);
493 } 494 }
494 } 495 }
495 #endif // defined(OS_WIN) 496 #endif // defined(OS_WIN)
496 497
497 } // namespace 498 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_toolstrip_api.cc ('k') | chrome/browser/extensions/extensions_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698