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
3 // found in the LICENSE file.
7 #include "chrome/browser/extensions/activity_log/activity_log.h"
8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "extensions/common/extension_builder.h"
11 #include "net/dns/mock_host_resolver.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h"
13 #include "net/test/embedded_test_server/http_request.h"
14 #include "net/test/embedded_test_server/http_response.h"
16 #if defined(OS_MACOSX)
17 #include "base/mac/mac_util.h"
20 using net::test_server::BasicHttpResponse
;
21 using net::test_server::HttpResponse
;
22 using net::test_server::HttpRequest
;
24 namespace extensions
{
26 class ActivityLogApiTest
: public ExtensionApiTest
{
28 ActivityLogApiTest() : saved_cmdline_(base::CommandLine::NO_PROGRAM
) {}
30 ~ActivityLogApiTest() override
{
31 ExtensionApiTest::SetUpCommandLine(&saved_cmdline_
);
32 *base::CommandLine::ForCurrentProcess() = saved_cmdline_
;
35 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
36 ExtensionApiTest::SetUpCommandLine(command_line
);
37 saved_cmdline_
= *base::CommandLine::ForCurrentProcess();
38 command_line
->AppendSwitch(switches::kEnableExtensionActivityLogging
);
41 scoped_ptr
<HttpResponse
> HandleRequest(const HttpRequest
& request
) {
42 scoped_ptr
<BasicHttpResponse
> response(new BasicHttpResponse
);
43 response
->set_code(net::HTTP_OK
);
44 response
->set_content("<html><head><title>ActivityLogTest</title>"
45 "</head><body>Hello World</body></html>");
46 return response
.Pass();
50 base::CommandLine saved_cmdline_
;
53 #if defined(OS_WIN) && !defined(NDEBUG)
54 // TODO(pmarch): fix flakiness on win debug - crbug.com/299393
55 #define MAYBE_TriggerEvent DISABLED_TriggerEvent
57 #define MAYBE_TriggerEvent TriggerEvent
60 // The test extension sends a message to its 'friend'. The test completes
61 // if it successfully sees the 'friend' receive the message.
62 IN_PROC_BROWSER_TEST_F(ActivityLogApiTest
, MAYBE_TriggerEvent
) {
63 #if defined(OS_MACOSX)
64 if (base::mac::IsOSSnowLeopard()) {
65 // This test flakes on 10.6 only. http://crbug.com/499176
69 ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(true);
71 host_resolver()->AddRule("*", "127.0.0.1");
72 ASSERT_TRUE(StartEmbeddedTestServer());
73 embedded_test_server()->RegisterRequestHandler(
74 base::Bind(&ActivityLogApiTest::HandleRequest
, base::Unretained(this)));
76 const Extension
* friend_extension
= LoadExtensionIncognito(
77 test_data_dir_
.AppendASCII("activity_log_private/friend"));
78 ASSERT_TRUE(friend_extension
);
79 ASSERT_TRUE(RunExtensionTest("activity_log_private/test"));
80 ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(false);
83 } // namespace extensions