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 "content/common/notification_service.h" | 16 #include "content/common/notification_service.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // 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 |
20 // to be returned by chrome.test.getConfig(). Do this by calling | 21 // to be returned by chrome.test.getConfig(). Do this by calling |
21 // ExtensionTestGetConfigFunction::set_test_config_state(Value* state) | 22 // ExtensionTestGetConfigFunction::set_test_config_state(Value* state) |
22 // in test set up. | 23 // in test set up. |
23 const char kNoTestConfigDataError[] = "Test configuration was not set."; | 24 const char kNoTestConfigDataError[] = "Test configuration was not set."; |
24 | 25 |
25 } // namespace | 26 } // namespace |
26 | 27 |
27 ExtensionTestPassFunction::~ExtensionTestPassFunction() {} | 28 ExtensionTestPassFunction::~ExtensionTestPassFunction() {} |
28 | 29 |
29 bool ExtensionTestPassFunction::RunImpl() { | 30 bool ExtensionTestPassFunction::RunImpl() { |
30 NotificationService::current()->Notify( | 31 NotificationService::current()->Notify( |
31 NotificationType::EXTENSION_TEST_PASSED, | 32 chrome::NOTIFICATION_EXTENSION_TEST_PASSED, |
32 Source<Profile>(dispatcher()->profile()), | 33 Source<Profile>(dispatcher()->profile()), |
33 NotificationService::NoDetails()); | 34 NotificationService::NoDetails()); |
34 return true; | 35 return true; |
35 } | 36 } |
36 | 37 |
37 ExtensionTestFailFunction::~ExtensionTestFailFunction() {} | 38 ExtensionTestFailFunction::~ExtensionTestFailFunction() {} |
38 | 39 |
39 bool ExtensionTestFailFunction::RunImpl() { | 40 bool ExtensionTestFailFunction::RunImpl() { |
40 std::string message; | 41 std::string message; |
41 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message)); | 42 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message)); |
42 NotificationService::current()->Notify( | 43 NotificationService::current()->Notify( |
43 NotificationType::EXTENSION_TEST_FAILED, | 44 chrome::NOTIFICATION_EXTENSION_TEST_FAILED, |
44 Source<Profile>(dispatcher()->profile()), | 45 Source<Profile>(dispatcher()->profile()), |
45 Details<std::string>(&message)); | 46 Details<std::string>(&message)); |
46 return true; | 47 return true; |
47 } | 48 } |
48 | 49 |
49 ExtensionTestLogFunction::~ExtensionTestLogFunction() {} | 50 ExtensionTestLogFunction::~ExtensionTestLogFunction() {} |
50 | 51 |
51 bool ExtensionTestLogFunction::RunImpl() { | 52 bool ExtensionTestLogFunction::RunImpl() { |
52 std::string message; | 53 std::string message; |
53 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message)); | 54 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message)); |
(...skipping 19 matching lines...) Expand all Loading... |
73 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); | 74 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); |
74 Browser::OpenURLOffTheRecord(profile(), GURL(url)); | 75 Browser::OpenURLOffTheRecord(profile(), GURL(url)); |
75 return true; | 76 return true; |
76 } | 77 } |
77 | 78 |
78 bool ExtensionTestSendMessageFunction::RunImpl() { | 79 bool ExtensionTestSendMessageFunction::RunImpl() { |
79 std::string message; | 80 std::string message; |
80 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message)); | 81 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message)); |
81 AddRef(); // balanced in Reply | 82 AddRef(); // balanced in Reply |
82 NotificationService::current()->Notify( | 83 NotificationService::current()->Notify( |
83 NotificationType::EXTENSION_TEST_MESSAGE, | 84 chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, |
84 Source<ExtensionTestSendMessageFunction>(this), | 85 Source<ExtensionTestSendMessageFunction>(this), |
85 Details<std::string>(&message)); | 86 Details<std::string>(&message)); |
86 return true; | 87 return true; |
87 } | 88 } |
88 ExtensionTestSendMessageFunction::~ExtensionTestSendMessageFunction() {} | 89 ExtensionTestSendMessageFunction::~ExtensionTestSendMessageFunction() {} |
89 | 90 |
90 void ExtensionTestSendMessageFunction::Reply(const std::string& message) { | 91 void ExtensionTestSendMessageFunction::Reply(const std::string& message) { |
91 result_.reset(Value::CreateStringValue(message)); | 92 result_.reset(Value::CreateStringValue(message)); |
92 SendResponse(true); | 93 SendResponse(true); |
93 Release(); // balanced in RunImpl | 94 Release(); // balanced in RunImpl |
(...skipping 21 matching lines...) Expand all Loading... |
115 TestConfigState* test_config_state = TestConfigState::GetInstance(); | 116 TestConfigState* test_config_state = TestConfigState::GetInstance(); |
116 | 117 |
117 if (!test_config_state->config_state()) { | 118 if (!test_config_state->config_state()) { |
118 error_ = kNoTestConfigDataError; | 119 error_ = kNoTestConfigDataError; |
119 return false; | 120 return false; |
120 } | 121 } |
121 | 122 |
122 result_.reset(test_config_state->config_state()->DeepCopy()); | 123 result_.reset(test_config_state->config_state()->DeepCopy()); |
123 return true; | 124 return true; |
124 } | 125 } |
OLD | NEW |