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 using net::test_server::BasicHttpResponse
;
17 using net::test_server::HttpResponse
;
18 using net::test_server::HttpRequest
;
20 namespace extensions
{
22 class ActivityLogApiTest
: public ExtensionApiTest
{
24 ActivityLogApiTest() : saved_cmdline_(base::CommandLine::NO_PROGRAM
) {}
26 ~ActivityLogApiTest() override
{
27 ExtensionApiTest::SetUpCommandLine(&saved_cmdline_
);
28 *base::CommandLine::ForCurrentProcess() = saved_cmdline_
;
31 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
32 ExtensionApiTest::SetUpCommandLine(command_line
);
33 saved_cmdline_
= *base::CommandLine::ForCurrentProcess();
34 command_line
->AppendSwitch(switches::kEnableExtensionActivityLogging
);
37 scoped_ptr
<HttpResponse
> HandleRequest(const HttpRequest
& request
) {
38 scoped_ptr
<BasicHttpResponse
> response(new BasicHttpResponse
);
39 response
->set_code(net::HTTP_OK
);
40 response
->set_content("<html><head><title>ActivityLogTest</title>"
41 "</head><body>Hello World</body></html>");
42 return response
.Pass();
46 base::CommandLine saved_cmdline_
;
49 #if defined(OS_WIN) && !defined(NDEBUG)
50 // TODO(pmarch): fix flakiness on win debug - crbug.com/299393
51 #define MAYBE_TriggerEvent DISABLED_TriggerEvent
53 #define MAYBE_TriggerEvent TriggerEvent
56 // The test extension sends a message to its 'friend'. The test completes
57 // if it successfully sees the 'friend' receive the message.
58 IN_PROC_BROWSER_TEST_F(ActivityLogApiTest
, MAYBE_TriggerEvent
) {
59 ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(true);
61 host_resolver()->AddRule("*", "127.0.0.1");
62 ASSERT_TRUE(StartEmbeddedTestServer());
63 embedded_test_server()->RegisterRequestHandler(
64 base::Bind(&ActivityLogApiTest::HandleRequest
, base::Unretained(this)));
66 const Extension
* friend_extension
= LoadExtensionIncognito(
67 test_data_dir_
.AppendASCII("activity_log_private/friend"));
68 ASSERT_TRUE(friend_extension
);
69 ASSERT_TRUE(RunExtensionTest("activity_log_private/test"));
70 ActivityLog::GetInstance(profile())->SetWatchdogAppActiveForTesting(false);
73 } // namespace extensions