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/user_style_sheet_watcher.h" | 5 #include "chrome/browser/user_style_sheet_watcher.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 base::ScopedTempDir dir; | 21 base::ScopedTempDir dir; |
22 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 22 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
23 | 23 |
24 std::string css_file_contents = "a { color: green; }"; | 24 std::string css_file_contents = "a { color: green; }"; |
25 base::FilePath style_sheet_file = dir.path().AppendASCII("User StyleSheets") | 25 base::FilePath style_sheet_file = dir.path().AppendASCII("User StyleSheets") |
26 .AppendASCII("Custom.css"); | 26 .AppendASCII("Custom.css"); |
27 file_util::CreateDirectory(style_sheet_file.DirName()); | 27 file_util::CreateDirectory(style_sheet_file.DirName()); |
28 ASSERT_TRUE(file_util::WriteFile(style_sheet_file, | 28 ASSERT_TRUE(file_util::WriteFile(style_sheet_file, |
29 css_file_contents.data(), css_file_contents.length())); | 29 css_file_contents.data(), css_file_contents.length())); |
30 | 30 |
31 MessageLoop loop(MessageLoop::TYPE_UI); | 31 base::MessageLoop loop(base::MessageLoop::TYPE_UI); |
32 base::Thread io_thread("UserStyleSheetWatcherTestIOThread"); | 32 base::Thread io_thread("UserStyleSheetWatcherTestIOThread"); |
33 base::Thread::Options options(MessageLoop::TYPE_IO, 0); | 33 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
34 ASSERT_TRUE(io_thread.StartWithOptions(options)); | 34 ASSERT_TRUE(io_thread.StartWithOptions(options)); |
35 content::TestBrowserThread browser_ui_thread(BrowserThread::UI, &loop); | 35 content::TestBrowserThread browser_ui_thread(BrowserThread::UI, &loop); |
36 content::TestBrowserThread browser_file_thread(BrowserThread::FILE, | 36 content::TestBrowserThread browser_file_thread(BrowserThread::FILE, |
37 io_thread.message_loop()); | 37 io_thread.message_loop()); |
38 | 38 |
39 // It is important that the creation of |style_sheet_watcher| occur after the | 39 // It is important that the creation of |style_sheet_watcher| occur after the |
40 // creation of |browser_ui_thread| because UserStyleSheetWatchers are | 40 // creation of |browser_ui_thread| because UserStyleSheetWatchers are |
41 // restricted to being deleted only on UI browser threads. | 41 // restricted to being deleted only on UI browser threads. |
42 scoped_refptr<UserStyleSheetWatcher> style_sheet_watcher( | 42 scoped_refptr<UserStyleSheetWatcher> style_sheet_watcher( |
43 new UserStyleSheetWatcher(NULL, dir.path())); | 43 new UserStyleSheetWatcher(NULL, dir.path())); |
44 style_sheet_watcher->Init(); | 44 style_sheet_watcher->Init(); |
45 | 45 |
46 io_thread.Stop(); | 46 io_thread.Stop(); |
47 loop.RunUntilIdle(); | 47 loop.RunUntilIdle(); |
48 | 48 |
49 GURL result_url = style_sheet_watcher->user_style_sheet(); | 49 GURL result_url = style_sheet_watcher->user_style_sheet(); |
50 std::string result = result_url.spec(); | 50 std::string result = result_url.spec(); |
51 std::string prefix = "data:text/css;charset=utf-8;base64,"; | 51 std::string prefix = "data:text/css;charset=utf-8;base64,"; |
52 ASSERT_TRUE(StartsWithASCII(result, prefix, true)); | 52 ASSERT_TRUE(StartsWithASCII(result, prefix, true)); |
53 result = result.substr(prefix.length()); | 53 result = result.substr(prefix.length()); |
54 std::string decoded; | 54 std::string decoded; |
55 ASSERT_TRUE(base::Base64Decode(result, &decoded)); | 55 ASSERT_TRUE(base::Base64Decode(result, &decoded)); |
56 ASSERT_EQ(css_file_contents, decoded); | 56 ASSERT_EQ(css_file_contents, decoded); |
57 } | 57 } |
OLD | NEW |