OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 <fstream> | 7 #include <fstream> |
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" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 base::SharedMemory* shared_memory_; | 67 base::SharedMemory* shared_memory_; |
68 }; | 68 }; |
69 | 69 |
70 // Test that we *don't* get spurious notifications. | 70 // Test that we *don't* get spurious notifications. |
71 TEST_F(UserScriptMasterTest, NoScripts) { | 71 TEST_F(UserScriptMasterTest, NoScripts) { |
72 // Set shared_memory_ to something non-NULL, so we can check it became NULL. | 72 // Set shared_memory_ to something non-NULL, so we can check it became NULL. |
73 shared_memory_ = reinterpret_cast<base::SharedMemory*>(1); | 73 shared_memory_ = reinterpret_cast<base::SharedMemory*>(1); |
74 | 74 |
75 scoped_refptr<UserScriptMaster> master( | 75 scoped_refptr<UserScriptMaster> master( |
76 new UserScriptMaster(MessageLoop::current(), script_dir_)); | 76 new UserScriptMaster(MessageLoop::current(), script_dir_)); |
| 77 master->StartScan(); |
77 message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); | 78 message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); |
78 message_loop_.Run(); | 79 message_loop_.Run(); |
79 | 80 |
80 // There were no scripts in the script dir, so we shouldn't have gotten | 81 // There were no scripts in the script dir, so we shouldn't have gotten |
81 // a notification. | 82 // a notification. |
82 ASSERT_EQ(NULL, shared_memory_); | 83 ASSERT_EQ(NULL, shared_memory_); |
83 } | 84 } |
84 | 85 |
85 // Test that we get notified about new scripts after they're added. | 86 // Test that we get notified about new scripts after they're added. |
86 TEST_F(UserScriptMasterTest, NewScripts) { | 87 TEST_F(UserScriptMasterTest, NewScripts) { |
(...skipping 16 matching lines...) Expand all Loading... |
103 TEST_F(UserScriptMasterTest, ExistingScripts) { | 104 TEST_F(UserScriptMasterTest, ExistingScripts) { |
104 FilePath path = script_dir_.AppendASCII("script.user.js"); | 105 FilePath path = script_dir_.AppendASCII("script.user.js"); |
105 | 106 |
106 FILE* file = file_util::OpenFile(path, "w"); | 107 FILE* file = file_util::OpenFile(path, "w"); |
107 const char content[] = "some content"; | 108 const char content[] = "some content"; |
108 fwrite(content, 1, arraysize(content), file); | 109 fwrite(content, 1, arraysize(content), file); |
109 file_util::CloseFile(file); | 110 file_util::CloseFile(file); |
110 | 111 |
111 scoped_refptr<UserScriptMaster> master( | 112 scoped_refptr<UserScriptMaster> master( |
112 new UserScriptMaster(MessageLoop::current(), script_dir_)); | 113 new UserScriptMaster(MessageLoop::current(), script_dir_)); |
| 114 master->StartScan(); |
113 | 115 |
114 message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); | 116 message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); |
115 message_loop_.Run(); | 117 message_loop_.Run(); |
116 | 118 |
117 ASSERT_TRUE(shared_memory_ != NULL); | 119 ASSERT_TRUE(shared_memory_ != NULL); |
118 } | 120 } |
119 | 121 |
120 TEST_F(UserScriptMasterTest, Parse1) { | 122 TEST_F(UserScriptMasterTest, Parse1) { |
121 const std::string text( | 123 const std::string text( |
122 "// This is my awesome script\n" | 124 "// This is my awesome script\n" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 const std::string text( | 158 const std::string text( |
157 "// ==UserScript==\n" | 159 "// ==UserScript==\n" |
158 "// @include *foo*\n" | 160 "// @include *foo*\n" |
159 "// ==/UserScript=="); // no trailing newline | 161 "// ==/UserScript=="); // no trailing newline |
160 | 162 |
161 std::vector<std::string> includes; | 163 std::vector<std::string> includes; |
162 UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &includes); | 164 UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &includes); |
163 EXPECT_EQ(1U, includes.size()); | 165 EXPECT_EQ(1U, includes.size()); |
164 EXPECT_EQ("*foo*", includes[0]); | 166 EXPECT_EQ("*foo*", includes[0]); |
165 } | 167 } |
OLD | NEW |