OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/extensions/extension_test_api.h" | 5 #include "chrome/browser/extensions/extension_test_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 11 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
12 #include "chrome/browser/extensions/extensions_quota_service.h" | 12 #include "chrome/browser/extensions/extensions_quota_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "content/common/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // If you see this error in your test, you need to set the config state | 20 // If you see this error in your test, you need to set the config state |
21 // to be returned by chrome.test.getConfig(). Do this by calling | 21 // to be returned by chrome.test.getConfig(). Do this by calling |
22 // ExtensionTestGetConfigFunction::set_test_config_state(Value* state) | 22 // ExtensionTestGetConfigFunction::set_test_config_state(Value* state) |
23 // in test set up. | 23 // in test set up. |
24 const char kNoTestConfigDataError[] = "Test configuration was not set."; | 24 const char kNoTestConfigDataError[] = "Test configuration was not set."; |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 ExtensionTestPassFunction::~ExtensionTestPassFunction() {} | 28 ExtensionTestPassFunction::~ExtensionTestPassFunction() {} |
29 | 29 |
30 bool ExtensionTestPassFunction::RunImpl() { | 30 bool ExtensionTestPassFunction::RunImpl() { |
31 NotificationService::current()->Notify( | 31 content::NotificationService::current()->Notify( |
32 chrome::NOTIFICATION_EXTENSION_TEST_PASSED, | 32 chrome::NOTIFICATION_EXTENSION_TEST_PASSED, |
33 content::Source<Profile>(dispatcher()->profile()), | 33 content::Source<Profile>(dispatcher()->profile()), |
34 NotificationService::NoDetails()); | 34 content::NotificationService::NoDetails()); |
35 return true; | 35 return true; |
36 } | 36 } |
37 | 37 |
38 ExtensionTestFailFunction::~ExtensionTestFailFunction() {} | 38 ExtensionTestFailFunction::~ExtensionTestFailFunction() {} |
39 | 39 |
40 bool ExtensionTestFailFunction::RunImpl() { | 40 bool ExtensionTestFailFunction::RunImpl() { |
41 std::string message; | 41 std::string message; |
42 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message)); | 42 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message)); |
43 NotificationService::current()->Notify( | 43 content::NotificationService::current()->Notify( |
44 chrome::NOTIFICATION_EXTENSION_TEST_FAILED, | 44 chrome::NOTIFICATION_EXTENSION_TEST_FAILED, |
45 content::Source<Profile>(dispatcher()->profile()), | 45 content::Source<Profile>(dispatcher()->profile()), |
46 content::Details<std::string>(&message)); | 46 content::Details<std::string>(&message)); |
47 return true; | 47 return true; |
48 } | 48 } |
49 | 49 |
50 ExtensionTestLogFunction::~ExtensionTestLogFunction() {} | 50 ExtensionTestLogFunction::~ExtensionTestLogFunction() {} |
51 | 51 |
52 bool ExtensionTestLogFunction::RunImpl() { | 52 bool ExtensionTestLogFunction::RunImpl() { |
53 std::string message; | 53 std::string message; |
(...skipping 19 matching lines...) Expand all Loading... |
73 std::string url; | 73 std::string url; |
74 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); | 74 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); |
75 Browser::OpenURLOffTheRecord(profile(), GURL(url)); | 75 Browser::OpenURLOffTheRecord(profile(), GURL(url)); |
76 return true; | 76 return true; |
77 } | 77 } |
78 | 78 |
79 bool ExtensionTestSendMessageFunction::RunImpl() { | 79 bool ExtensionTestSendMessageFunction::RunImpl() { |
80 std::string message; | 80 std::string message; |
81 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message)); | 81 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message)); |
82 AddRef(); // balanced in Reply | 82 AddRef(); // balanced in Reply |
83 NotificationService::current()->Notify( | 83 content::NotificationService::current()->Notify( |
84 chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, | 84 chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, |
85 content::Source<ExtensionTestSendMessageFunction>(this), | 85 content::Source<ExtensionTestSendMessageFunction>(this), |
86 content::Details<std::string>(&message)); | 86 content::Details<std::string>(&message)); |
87 return true; | 87 return true; |
88 } | 88 } |
89 ExtensionTestSendMessageFunction::~ExtensionTestSendMessageFunction() {} | 89 ExtensionTestSendMessageFunction::~ExtensionTestSendMessageFunction() {} |
90 | 90 |
91 void ExtensionTestSendMessageFunction::Reply(const std::string& message) { | 91 void ExtensionTestSendMessageFunction::Reply(const std::string& message) { |
92 result_.reset(Value::CreateStringValue(message)); | 92 result_.reset(Value::CreateStringValue(message)); |
93 SendResponse(true); | 93 SendResponse(true); |
(...skipping 22 matching lines...) Expand all Loading... |
116 TestConfigState* test_config_state = TestConfigState::GetInstance(); | 116 TestConfigState* test_config_state = TestConfigState::GetInstance(); |
117 | 117 |
118 if (!test_config_state->config_state()) { | 118 if (!test_config_state->config_state()) { |
119 error_ = kNoTestConfigDataError; | 119 error_ = kNoTestConfigDataError; |
120 return false; | 120 return false; |
121 } | 121 } |
122 | 122 |
123 result_.reset(test_config_state->config_state()->DeepCopy()); | 123 result_.reset(test_config_state->config_state()->DeepCopy()); |
124 return true; | 124 return true; |
125 } | 125 } |
OLD | NEW |