| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/extensions/user_script_master.h" | 5 #include "chrome/browser/extensions/user_script_master.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/common/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 24 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
| 25 int schemes = URLPattern::SCHEME_ALL; | 25 int schemes = URLPattern::SCHEME_ALL; |
| 26 extent->AddPattern(URLPattern(schemes, pattern)); | 26 extent->AddPattern(URLPattern(schemes, pattern)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 } | 29 } |
| 30 | 30 |
| 31 // Test bringing up a master on a specific directory, putting a script | 31 // Test bringing up a master on a specific directory, putting a script |
| 32 // in there, etc. | 32 // in there, etc. |
| 33 | 33 |
| 34 class UserScriptMasterTest : public testing::Test, | 34 class UserScriptMasterTest : public testing::Test, |
| 35 public content::NotificationObserver { | 35 public content::NotificationObserver { |
| 36 public: | 36 public: |
| 37 UserScriptMasterTest() | 37 UserScriptMasterTest() |
| 38 : message_loop_(MessageLoop::TYPE_UI), | 38 : message_loop_(MessageLoop::TYPE_UI), |
| 39 shared_memory_(NULL) { | 39 shared_memory_(NULL) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 virtual void SetUp() { | 42 virtual void SetUp() { |
| 43 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 43 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 44 | 44 |
| 45 // Register for all user script notifications. | 45 // Register for all user script notifications. |
| 46 registrar_.Add(this, chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 46 registrar_.Add(this, chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
| 47 NotificationService::AllSources()); | 47 content::NotificationService::AllSources()); |
| 48 | 48 |
| 49 // UserScriptMaster posts tasks to the file thread so make the current | 49 // UserScriptMaster posts tasks to the file thread so make the current |
| 50 // thread look like one. | 50 // thread look like one. |
| 51 file_thread_.reset(new BrowserThread( | 51 file_thread_.reset(new BrowserThread( |
| 52 BrowserThread::FILE, MessageLoop::current())); | 52 BrowserThread::FILE, MessageLoop::current())); |
| 53 ui_thread_.reset(new BrowserThread( | 53 ui_thread_.reset(new BrowserThread( |
| 54 BrowserThread::UI, MessageLoop::current())); | 54 BrowserThread::UI, MessageLoop::current())); |
| 55 } | 55 } |
| 56 | 56 |
| 57 virtual void TearDown() { | 57 virtual void TearDown() { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 user_scripts.push_back(user_script); | 243 user_scripts.push_back(user_script); |
| 244 | 244 |
| 245 UserScriptMaster::ScriptReloader* script_reloader = | 245 UserScriptMaster::ScriptReloader* script_reloader = |
| 246 new UserScriptMaster::ScriptReloader(NULL); | 246 new UserScriptMaster::ScriptReloader(NULL); |
| 247 script_reloader->AddRef(); | 247 script_reloader->AddRef(); |
| 248 script_reloader->LoadUserScripts(&user_scripts); | 248 script_reloader->LoadUserScripts(&user_scripts); |
| 249 script_reloader->Release(); | 249 script_reloader->Release(); |
| 250 | 250 |
| 251 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); | 251 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); |
| 252 } | 252 } |
| OLD | NEW |