Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / activity_log_private / activity_log_private_apitest.cc
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.
4
5 #include <string>
6
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"
15
16 using net::test_server::BasicHttpResponse;
17 using net::test_server::HttpResponse;
18 using net::test_server::HttpRequest;
19
20 namespace extensions {
21
22 class ActivityLogApiTest : public ExtensionApiTest {
23  public:
24   ActivityLogApiTest() : saved_cmdline_(CommandLine::NO_PROGRAM) {}
25
26   virtual ~ActivityLogApiTest() {
27     ExtensionApiTest::SetUpCommandLine(&saved_cmdline_);
28     *CommandLine::ForCurrentProcess() = saved_cmdline_;
29   }
30
31   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
32     ExtensionApiTest::SetUpCommandLine(command_line);
33     saved_cmdline_ = *CommandLine::ForCurrentProcess();
34     command_line->AppendSwitch(switches::kEnableExtensionActivityLogging);
35   }
36
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.PassAs<HttpResponse>();
43   }
44
45  private:
46   CommandLine saved_cmdline_;
47 };
48
49 #if defined(OS_WIN) && !defined(NDEBUG)
50 // TODO(karenlees): fix flakiness on win debug - crbug.com/299393
51 #define MAYBE_TriggerEvent DISABLED_TriggerEvent
52 #else
53 #define MAYBE_TriggerEvent TriggerEvent
54 #endif
55
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);
60
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)));
65
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);
71 }
72
73 }  // namespace extensions
74