Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 "base/command_line.h" | |
| 6 #include "base/memory/scoped_ptr.h" | |
| 7 #include "base/message_loop.h" | |
| 8 #include "base/synchronization/waitable_event.h" | |
| 9 #include "chrome/browser/extensions/activity_log/activity_log.h" | |
| 10 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" | |
| 11 #include "chrome/browser/extensions/extension_service.h" | |
| 12 #include "chrome/browser/extensions/test_extension_system.h" | |
| 13 #include "chrome/common/chrome_constants.h" | |
| 14 #include "chrome/common/chrome_switches.h" | |
| 15 #include "chrome/common/extensions/extension_builder.h" | |
| 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 17 #include "chrome/test/base/testing_profile.h" | |
| 18 #include "content/public/browser/browser_thread.h" | |
| 19 #include "content/public/test/test_browser_thread.h" | |
| 20 #include "sql/statement.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 | |
| 23 #if defined(OS_CHROMEOS) | |
| 24 #include "chrome/browser/chromeos/login/user_manager.h" | |
| 25 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
| 26 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
| 27 #endif | |
| 28 | |
| 29 namespace extensions { | |
| 30 | |
| 31 class FullStreamUIPolicyTest : public ChromeRenderViewHostTestHarness { | |
| 32 public: | |
| 33 FullStreamUIPolicyTest() | |
| 34 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), | |
| 35 db_thread_(BrowserThread::DB, base::MessageLoop::current()), | |
| 36 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {} | |
|
felt
2013/06/13 20:24:16
Hey, there were a bunch of changes made to the act
dbabic
2013/06/13 23:10:08
Done.
| |
| 37 | |
| 38 | |
| 39 virtual void SetUp() OVERRIDE { | |
| 40 ChromeRenderViewHostTestHarness::SetUp(); | |
| 41 CommandLine command_line(CommandLine::NO_PROGRAM); | |
| 42 profile_ = | |
| 43 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
| 44 extension_service_ = static_cast<TestExtensionSystem*>( | |
| 45 ExtensionSystem::Get(profile_))->CreateExtensionService( | |
| 46 &command_line, base::FilePath(), false); | |
| 47 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 48 switches::kEnableExtensionActivityLogTesting); | |
| 49 } | |
| 50 | |
| 51 virtual ~FullStreamUIPolicyTest() { | |
| 52 base::MessageLoop::current()->PostTask(FROM_HERE, | |
| 53 base::MessageLoop::QuitClosure()); | |
| 54 base::MessageLoop::current()->Run(); | |
| 55 } | |
| 56 | |
| 57 static void RetrieveActions_LogAndFetchActions( | |
| 58 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | |
| 59 ASSERT_EQ(2, static_cast<int>(i->size())); | |
| 60 } | |
| 61 | |
| 62 static void Arguments_Present( | |
| 63 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | |
| 64 scoped_refptr<Action> last = i->front(); | |
| 65 std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " | |
| 66 "CALL, API: extension.connect, ARGS: \"hello\", \"world\""; | |
| 67 ASSERT_EQ(args, last->PrintForDebug()); | |
| 68 } | |
| 69 | |
| 70 protected: | |
| 71 ExtensionService* extension_service_; | |
| 72 Profile* profile_; | |
| 73 | |
| 74 private: | |
| 75 content::TestBrowserThread ui_thread_; | |
| 76 content::TestBrowserThread db_thread_; | |
| 77 content::TestBrowserThread file_thread_; | |
| 78 | |
| 79 #if defined OS_CHROMEOS | |
| 80 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | |
| 81 chromeos::ScopedTestCrosSettings test_cros_settings_; | |
| 82 chromeos::ScopedTestUserManager test_user_manager_; | |
| 83 #endif | |
| 84 }; | |
| 85 | |
| 86 TEST_F(FullStreamUIPolicyTest, Construct) { | |
| 87 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_, | |
| 88 BrowserThread::UI); | |
| 89 scoped_refptr<const Extension> extension = | |
| 90 ExtensionBuilder() | |
| 91 .SetManifest(DictionaryBuilder() | |
| 92 .Set("name", "Test extension") | |
| 93 .Set("version", "1.0.0") | |
| 94 .Set("manifest_version", 2)) | |
| 95 .Build(); | |
| 96 extension_service_->AddExtension(extension); | |
| 97 scoped_ptr<ListValue> args(new ListValue()); | |
| 98 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), | |
| 99 std::string("tabs.testMethod"), NULL, args.get(), NULL); | |
| 100 delete policy; | |
| 101 } | |
| 102 | |
| 103 TEST_F(FullStreamUIPolicyTest, LogAndFetchActions) { | |
| 104 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_, | |
| 105 BrowserThread::UI); | |
| 106 scoped_refptr<const Extension> extension = | |
| 107 ExtensionBuilder() | |
| 108 .SetManifest(DictionaryBuilder() | |
| 109 .Set("name", "Test extension") | |
| 110 .Set("version", "1.0.0") | |
| 111 .Set("manifest_version", 2)) | |
| 112 .Build(); | |
| 113 extension_service_->AddExtension(extension); | |
| 114 scoped_ptr<ListValue> args(new ListValue()); | |
| 115 GURL* gurl = new GURL("http://www.google.com"); | |
| 116 | |
| 117 // Write some API calls | |
| 118 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), | |
| 119 std::string("tabs.testMethod"), NULL, args.get(), NULL); | |
| 120 policy->ProcessAction(ActivityLogPolicy::ACTION_DOM, | |
| 121 extension->id(), std::string("document.write"), gurl, args.get(), NULL); | |
| 122 policy->ReadData(extension->id(), 0, | |
| 123 base::Bind(FullStreamUIPolicyTest::RetrieveActions_LogAndFetchActions)); | |
| 124 delete policy; | |
| 125 delete gurl; | |
| 126 } | |
| 127 | |
| 128 TEST_F(FullStreamUIPolicyTest, LogWithArguments) { | |
| 129 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_, | |
| 130 BrowserThread::UI); | |
| 131 scoped_refptr<const Extension> extension = | |
| 132 ExtensionBuilder() | |
| 133 .SetManifest(DictionaryBuilder() | |
| 134 .Set("name", "Test extension") | |
| 135 .Set("version", "1.0.0") | |
| 136 .Set("manifest_version", 2)) | |
| 137 .Build(); | |
| 138 extension_service_->AddExtension(extension); | |
| 139 scoped_ptr<ListValue> args(new ListValue()); | |
| 140 args->Set(0, new base::StringValue("hello")); | |
| 141 args->Set(1, new base::StringValue("world")); | |
| 142 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), | |
| 143 std::string("extension.connect"), NULL, args.get(), NULL); | |
| 144 policy->ReadData(extension->id(), 0, | |
| 145 base::Bind(FullStreamUIPolicyTest::Arguments_Present)); | |
| 146 } | |
| 147 | |
| 148 } // namespace extensions | |
| OLD | NEW |