Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Side by Side Diff: chrome/browser/user_style_sheet_watcher_unittest.cc

Issue 64843004: Get rid of user-level styles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge to ToT Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/user_style_sheet_watcher_factory.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/user_style_sheet_watcher.h"
6
7 #include "base/base64.h"
8 #include "base/basictypes.h"
9 #include "base/file_util.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/strings/string_util.h"
13 #include "base/threading/thread.h"
14 #include "chrome/test/base/testing_browser_process.h"
15 #include "content/public/test/test_browser_thread.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 using content::BrowserThread;
19
20 TEST(UserStyleSheetWatcherTest, StyleLoad) {
21 base::ScopedTempDir dir;
22 ASSERT_TRUE(dir.CreateUniqueTempDir());
23
24 std::string css_file_contents = "a { color: green; }";
25 base::FilePath style_sheet_file = dir.path().AppendASCII("User StyleSheets")
26 .AppendASCII("Custom.css");
27 file_util::CreateDirectory(style_sheet_file.DirName());
28 ASSERT_TRUE(file_util::WriteFile(style_sheet_file,
29 css_file_contents.data(), css_file_contents.length()));
30
31 base::MessageLoop loop(base::MessageLoop::TYPE_UI);
32 base::Thread io_thread("UserStyleSheetWatcherTestIOThread");
33 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
34 ASSERT_TRUE(io_thread.StartWithOptions(options));
35 content::TestBrowserThread browser_ui_thread(BrowserThread::UI, &loop);
36 content::TestBrowserThread browser_file_thread(BrowserThread::FILE,
37 io_thread.message_loop());
38
39 // It is important that the creation of |style_sheet_watcher| occur after the
40 // creation of |browser_ui_thread| because UserStyleSheetWatchers are
41 // restricted to being deleted only on UI browser threads.
42 scoped_refptr<UserStyleSheetWatcher> style_sheet_watcher(
43 new UserStyleSheetWatcher(NULL, dir.path()));
44 style_sheet_watcher->Init();
45
46 io_thread.Stop();
47 loop.RunUntilIdle();
48
49 GURL result_url = style_sheet_watcher->user_style_sheet();
50 std::string result = result_url.spec();
51 std::string prefix = "data:text/css;charset=utf-8;base64,";
52 ASSERT_TRUE(StartsWithASCII(result, prefix, true));
53 result = result.substr(prefix.length());
54 std::string decoded;
55 ASSERT_TRUE(base::Base64Decode(result, &decoded));
56 ASSERT_EQ(css_file_contents, decoded);
57 }
OLDNEW
« no previous file with comments | « chrome/browser/user_style_sheet_watcher_factory.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698