OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "chrome/browser/extensions/activity_log/activity_log.h" | 6 #include "chrome/browser/extensions/activity_log/activity_log.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_browsertest.h" | 8 #include "chrome/browser/extensions/extension_browsertest.h" |
9 #include "chrome/browser/prerender/prerender_handle.h" | 9 #include "chrome/browser/prerender/prerender_handle.h" |
10 #include "chrome/browser/prerender/prerender_manager.h" | 10 #include "chrome/browser/prerender/prerender_manager.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // Only the prerender tests are in this file. To add tests for activity | 22 // Only the prerender tests are in this file. To add tests for activity |
23 // logging please see: | 23 // logging please see: |
24 // chrome/test/data/extensions/api_test/activity_log_private/README | 24 // chrome/test/data/extensions/api_test/activity_log_private/README |
25 | 25 |
26 class ActivityLogPrerenderTest : public ExtensionApiTest { | 26 class ActivityLogPrerenderTest : public ExtensionApiTest { |
27 protected: | 27 protected: |
28 // Make sure the activity log is turned on. | 28 // Make sure the activity log is turned on. |
29 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 29 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
30 ExtensionBrowserTest::SetUpCommandLine(command_line); | 30 ExtensionBrowserTest::SetUpCommandLine(command_line); |
31 command_line->AppendSwitch(switches::kEnableExtensionActivityLogging); | 31 command_line->AppendSwitch(switches::kEnableExtensionActivityLogging); |
32 command_line->AppendSwitch(switches::kEnableExtensionActivityLogTesting); | |
33 command_line->AppendSwitchASCII(switches::kPrerenderMode, | 32 command_line->AppendSwitchASCII(switches::kPrerenderMode, |
34 switches::kPrerenderModeSwitchValueEnabled); | 33 switches::kPrerenderModeSwitchValueEnabled); |
35 } | 34 } |
36 | 35 |
37 static void Prerender_Arguments( | 36 static void Prerender_Arguments( |
38 const std::string& extension_id, | 37 const std::string& extension_id, |
39 int port, | 38 int port, |
40 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 39 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
41 // This is to exit RunLoop (base::MessageLoop::current()->Run()) below | 40 // This is to exit RunLoop (base::MessageLoop::current()->Run()) below |
42 base::MessageLoop::current()->PostTask( | 41 base::MessageLoop::current()->PostTask( |
43 FROM_HERE, base::MessageLoop::QuitClosure()); | 42 FROM_HERE, base::MessageLoop::QuitClosure()); |
44 | 43 |
45 ASSERT_TRUE(i->size()); | 44 ASSERT_TRUE(i->size()); |
46 scoped_refptr<Action> last = i->front(); | 45 scoped_refptr<Action> last = i->front(); |
47 | 46 |
48 std::string args = base::StringPrintf( | 47 ASSERT_EQ(Action::ACTION_CONTENT_SCRIPT, last->action_type()); |
49 "ID=%s CATEGORY=content_script API= ARGS=[\"/google_cs.js\"] " | 48 ASSERT_EQ("[\"/google_cs.js\"]", |
50 "PAGE_URL=http://www.google.com.bo:%d/test.html " | 49 ActivityLogPolicy::Util::Serialize(last->args())); |
51 "PAGE_TITLE=\"www.google.com.bo:%d/test.html\" " | 50 ASSERT_EQ(base::StringPrintf("http://www.google.com.bo:%d/test.html", port), |
52 "OTHER={\"prerender\":true}", | 51 last->page_url().spec()); |
53 extension_id.c_str(), port, port); | 52 ASSERT_EQ("{\"prerender\":true}", |
54 // TODO: Replace PrintForDebug with field testing | 53 ActivityLogPolicy::Util::Serialize(last->other())); |
55 // when this feature will be available | |
56 ASSERT_EQ(args, last->PrintForDebug()); | |
57 } | 54 } |
58 }; | 55 }; |
59 | 56 |
60 IN_PROC_BROWSER_TEST_F(ActivityLogPrerenderTest, TestScriptInjected) { | 57 IN_PROC_BROWSER_TEST_F(ActivityLogPrerenderTest, TestScriptInjected) { |
61 host_resolver()->AddRule("*", "127.0.0.1"); | 58 host_resolver()->AddRule("*", "127.0.0.1"); |
62 StartEmbeddedTestServer(); | 59 StartEmbeddedTestServer(); |
63 int port = embedded_test_server()->port(); | 60 int port = embedded_test_server()->port(); |
64 | 61 |
65 // Get the extension (chrome/test/data/extensions/activity_log) | 62 // Get the extension (chrome/test/data/extensions/activity_log) |
66 const Extension* ext = | 63 const Extension* ext = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 99 |
103 activity_log->GetActions( | 100 activity_log->GetActions( |
104 ext->id(), 0, base::Bind( | 101 ext->id(), 0, base::Bind( |
105 ActivityLogPrerenderTest::Prerender_Arguments, ext->id(), port)); | 102 ActivityLogPrerenderTest::Prerender_Arguments, ext->id(), port)); |
106 | 103 |
107 // Allow invocation of Prerender_Arguments | 104 // Allow invocation of Prerender_Arguments |
108 base::MessageLoop::current()->Run(); | 105 base::MessageLoop::current()->Run(); |
109 } | 106 } |
110 | 107 |
111 } // namespace extensions | 108 } // namespace extensions |
OLD | NEW |