OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "chrome/browser/extensions/activity_log/activity_log.h" | 7 #include "chrome/browser/extensions/activity_log/activity_log.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "extensions/common/extension_builder.h" | 10 #include "extensions/common/extension_builder.h" |
11 #include "net/dns/mock_host_resolver.h" | 11 #include "net/dns/mock_host_resolver.h" |
12 #include "net/test/embedded_test_server/embedded_test_server.h" | 12 #include "net/test/embedded_test_server/embedded_test_server.h" |
13 #include "net/test/embedded_test_server/http_request.h" | 13 #include "net/test/embedded_test_server/http_request.h" |
14 #include "net/test/embedded_test_server/http_response.h" | 14 #include "net/test/embedded_test_server/http_response.h" |
15 | 15 |
16 using net::test_server::BasicHttpResponse; | 16 using net::test_server::BasicHttpResponse; |
17 using net::test_server::HttpResponse; | 17 using net::test_server::HttpResponse; |
18 using net::test_server::HttpRequest; | 18 using net::test_server::HttpRequest; |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 class ActivityLogApiTest : public ExtensionApiTest { | 22 class ActivityLogApiTest : public ExtensionApiTest { |
23 public: | 23 public: |
24 ActivityLogApiTest() : saved_cmdline_(CommandLine::NO_PROGRAM) {} | 24 ActivityLogApiTest() : saved_cmdline_(base::CommandLine::NO_PROGRAM) {} |
25 | 25 |
26 ~ActivityLogApiTest() override { | 26 ~ActivityLogApiTest() override { |
27 ExtensionApiTest::SetUpCommandLine(&saved_cmdline_); | 27 ExtensionApiTest::SetUpCommandLine(&saved_cmdline_); |
28 *CommandLine::ForCurrentProcess() = saved_cmdline_; | 28 *base::CommandLine::ForCurrentProcess() = saved_cmdline_; |
29 } | 29 } |
30 | 30 |
31 void SetUpCommandLine(CommandLine* command_line) override { | 31 void SetUpCommandLine(base::CommandLine* command_line) override { |
32 ExtensionApiTest::SetUpCommandLine(command_line); | 32 ExtensionApiTest::SetUpCommandLine(command_line); |
33 saved_cmdline_ = *CommandLine::ForCurrentProcess(); | 33 saved_cmdline_ = *base::CommandLine::ForCurrentProcess(); |
34 command_line->AppendSwitch(switches::kEnableExtensionActivityLogging); | 34 command_line->AppendSwitch(switches::kEnableExtensionActivityLogging); |
35 } | 35 } |
36 | 36 |
37 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { | 37 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { |
38 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse); | 38 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse); |
39 response->set_code(net::HTTP_OK); | 39 response->set_code(net::HTTP_OK); |
40 response->set_content("<html><head><title>ActivityLogTest</title>" | 40 response->set_content("<html><head><title>ActivityLogTest</title>" |
41 "</head><body>Hello World</body></html>"); | 41 "</head><body>Hello World</body></html>"); |
42 return response.Pass(); | 42 return response.Pass(); |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 CommandLine saved_cmdline_; | 46 base::CommandLine saved_cmdline_; |
47 }; | 47 }; |
48 | 48 |
49 #if defined(OS_WIN) && !defined(NDEBUG) | 49 #if defined(OS_WIN) && !defined(NDEBUG) |
50 // TODO(pmarch): fix flakiness on win debug - crbug.com/299393 | 50 // TODO(pmarch): fix flakiness on win debug - crbug.com/299393 |
51 #define MAYBE_TriggerEvent DISABLED_TriggerEvent | 51 #define MAYBE_TriggerEvent DISABLED_TriggerEvent |
52 #else | 52 #else |
53 #define MAYBE_TriggerEvent TriggerEvent | 53 #define MAYBE_TriggerEvent TriggerEvent |
54 #endif | 54 #endif |
55 | 55 |
56 // The test extension sends a message to its 'friend'. The test completes | 56 // The test extension sends a message to its 'friend'. The test completes |
57 // if it successfully sees the 'friend' receive the message. | 57 // if it successfully sees the 'friend' receive the message. |
58 IN_PROC_BROWSER_TEST_F(ActivityLogApiTest, MAYBE_TriggerEvent) { | 58 IN_PROC_BROWSER_TEST_F(ActivityLogApiTest, MAYBE_TriggerEvent) { |
59 ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(true); | 59 ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(true); |
60 | 60 |
61 host_resolver()->AddRule("*", "127.0.0.1"); | 61 host_resolver()->AddRule("*", "127.0.0.1"); |
62 ASSERT_TRUE(StartEmbeddedTestServer()); | 62 ASSERT_TRUE(StartEmbeddedTestServer()); |
63 embedded_test_server()->RegisterRequestHandler( | 63 embedded_test_server()->RegisterRequestHandler( |
64 base::Bind(&ActivityLogApiTest::HandleRequest, base::Unretained(this))); | 64 base::Bind(&ActivityLogApiTest::HandleRequest, base::Unretained(this))); |
65 | 65 |
66 const Extension* friend_extension = LoadExtensionIncognito( | 66 const Extension* friend_extension = LoadExtensionIncognito( |
67 test_data_dir_.AppendASCII("activity_log_private/friend")); | 67 test_data_dir_.AppendASCII("activity_log_private/friend")); |
68 ASSERT_TRUE(friend_extension); | 68 ASSERT_TRUE(friend_extension); |
69 ASSERT_TRUE(RunExtensionTest("activity_log_private/test")); | 69 ASSERT_TRUE(RunExtensionTest("activity_log_private/test")); |
70 ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(false); | 70 ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(false); |
71 } | 71 } |
72 | 72 |
73 } // namespace extensions | 73 } // namespace extensions |
74 | 74 |
OLD | NEW |