| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
| 6 | 6 |
| 7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | |
| 11 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/unpacked_installer.h" | 11 #include "chrome/browser/extensions/unpacked_installer.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/extensions/application_launch.h" | 14 #include "chrome/browser/ui/extensions/application_launch.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 19 #include "extensions/browser/api/test/test_api.h" | 18 #include "extensions/browser/api/test/test_api.h" |
| 20 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
| 20 #include "extensions/browser/notification_types.h" |
| 21 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 22 #include "extensions/common/extension_set.h" | 22 #include "extensions/common/extension_set.h" |
| 23 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
| 24 #include "net/base/filename_util.h" | 24 #include "net/base/filename_util.h" |
| 25 #include "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 26 #include "net/test/embedded_test_server/http_request.h" | 26 #include "net/test/embedded_test_server/http_request.h" |
| 27 #include "net/test/embedded_test_server/http_response.h" | 27 #include "net/test/embedded_test_server/http_response.h" |
| 28 #include "net/test/spawned_test_server/spawned_test_server.h" | 28 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 base::Bind(&HandleSetCookieRequest)); | 137 base::Bind(&HandleSetCookieRequest)); |
| 138 embedded_test_server()->RegisterRequestHandler( | 138 embedded_test_server()->RegisterRequestHandler( |
| 139 base::Bind(&HandleSetHeaderRequest)); | 139 base::Bind(&HandleSetHeaderRequest)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 ExtensionApiTest::~ExtensionApiTest() {} | 142 ExtensionApiTest::~ExtensionApiTest() {} |
| 143 | 143 |
| 144 ExtensionApiTest::ResultCatcher::ResultCatcher() | 144 ExtensionApiTest::ResultCatcher::ResultCatcher() |
| 145 : profile_restriction_(NULL), | 145 : profile_restriction_(NULL), |
| 146 waiting_(false) { | 146 waiting_(false) { |
| 147 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_PASSED, | 147 registrar_.Add(this, |
| 148 extensions::NOTIFICATION_EXTENSION_TEST_PASSED, |
| 148 content::NotificationService::AllSources()); | 149 content::NotificationService::AllSources()); |
| 149 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_FAILED, | 150 registrar_.Add(this, |
| 151 extensions::NOTIFICATION_EXTENSION_TEST_FAILED, |
| 150 content::NotificationService::AllSources()); | 152 content::NotificationService::AllSources()); |
| 151 } | 153 } |
| 152 | 154 |
| 153 ExtensionApiTest::ResultCatcher::~ResultCatcher() { | 155 ExtensionApiTest::ResultCatcher::~ResultCatcher() { |
| 154 } | 156 } |
| 155 | 157 |
| 156 bool ExtensionApiTest::ResultCatcher::GetNextResult() { | 158 bool ExtensionApiTest::ResultCatcher::GetNextResult() { |
| 157 // Depending on the tests, multiple results can come in from a single call | 159 // Depending on the tests, multiple results can come in from a single call |
| 158 // to RunMessageLoop(), so we maintain a queue of results and just pull them | 160 // to RunMessageLoop(), so we maintain a queue of results and just pull them |
| 159 // off as the test calls this, going to the run loop only when the queue is | 161 // off as the test calls this, going to the run loop only when the queue is |
| (...skipping 18 matching lines...) Expand all Loading... |
| 178 | 180 |
| 179 void ExtensionApiTest::ResultCatcher::Observe( | 181 void ExtensionApiTest::ResultCatcher::Observe( |
| 180 int type, const content::NotificationSource& source, | 182 int type, const content::NotificationSource& source, |
| 181 const content::NotificationDetails& details) { | 183 const content::NotificationDetails& details) { |
| 182 if (profile_restriction_ && | 184 if (profile_restriction_ && |
| 183 content::Source<Profile>(source).ptr() != profile_restriction_) { | 185 content::Source<Profile>(source).ptr() != profile_restriction_) { |
| 184 return; | 186 return; |
| 185 } | 187 } |
| 186 | 188 |
| 187 switch (type) { | 189 switch (type) { |
| 188 case chrome::NOTIFICATION_EXTENSION_TEST_PASSED: | 190 case extensions::NOTIFICATION_EXTENSION_TEST_PASSED: |
| 189 VLOG(1) << "Got EXTENSION_TEST_PASSED notification."; | 191 VLOG(1) << "Got EXTENSION_TEST_PASSED notification."; |
| 190 results_.push_back(true); | 192 results_.push_back(true); |
| 191 messages_.push_back(std::string()); | 193 messages_.push_back(std::string()); |
| 192 if (waiting_) | 194 if (waiting_) |
| 193 base::MessageLoopForUI::current()->Quit(); | 195 base::MessageLoopForUI::current()->Quit(); |
| 194 break; | 196 break; |
| 195 | 197 |
| 196 case chrome::NOTIFICATION_EXTENSION_TEST_FAILED: | 198 case extensions::NOTIFICATION_EXTENSION_TEST_FAILED: |
| 197 VLOG(1) << "Got EXTENSION_TEST_FAILED notification."; | 199 VLOG(1) << "Got EXTENSION_TEST_FAILED notification."; |
| 198 results_.push_back(false); | 200 results_.push_back(false); |
| 199 messages_.push_back(*(content::Details<std::string>(details).ptr())); | 201 messages_.push_back(*(content::Details<std::string>(details).ptr())); |
| 200 if (waiting_) | 202 if (waiting_) |
| 201 base::MessageLoopForUI::current()->Quit(); | 203 base::MessageLoopForUI::current()->Quit(); |
| 202 break; | 204 break; |
| 203 | 205 |
| 204 default: | 206 default: |
| 205 NOTREACHED(); | 207 NOTREACHED(); |
| 206 } | 208 } |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 test_config_->SetInteger(kSpawnedTestServerPort, | 478 test_config_->SetInteger(kSpawnedTestServerPort, |
| 477 test_server()->host_port_pair().port()); | 479 test_server()->host_port_pair().port()); |
| 478 | 480 |
| 479 return true; | 481 return true; |
| 480 } | 482 } |
| 481 | 483 |
| 482 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { | 484 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { |
| 483 ExtensionBrowserTest::SetUpCommandLine(command_line); | 485 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 484 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); | 486 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); |
| 485 } | 487 } |
| OLD | NEW |