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

Side by Side Diff: chrome/browser/chromeos/display/quirks_browsertest.cc

Issue 1775023002: Enterprise policy to prevent queries to the Quirks Server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix display unit test Created 4 years, 8 months 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "chrome/test/base/in_process_browser_test.h" 8 #include "chrome/test/base/in_process_browser_test.h"
9 #include "components/quirks/quirks_manager.h" 9 #include "components/quirks/quirks_manager.h"
10 #include "components/quirks/switches.h" 10 #include "components/quirks/switches.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 } // namespace 50 } // namespace
51 51
52 class QuirksBrowserTest : public InProcessBrowserTest { 52 class QuirksBrowserTest : public InProcessBrowserTest {
53 public: 53 public:
54 QuirksBrowserTest() : file_existed_(false) {} 54 QuirksBrowserTest() : file_existed_(false) {}
55 55
56 protected: 56 protected:
57 ~QuirksBrowserTest() override = default; 57 ~QuirksBrowserTest() override = default;
58 58
59 void Initialize() {
60 // NOTE: QuirksManager::Initialize() isn't necessary here, since it'll be
61 // called in ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun().
62
63 // Create display_profiles subdirectory under temp profile directory.
64 const base::FilePath path =
65 QuirksManager::Get()->delegate()->GetDownloadDisplayProfileDirectory();
66 base::File::Error error = base::File::FILE_OK;
67 bool created = base::CreateDirectoryAndGetError(path, &error);
68 ASSERT_TRUE(created);
69
70 // Quirks clients can't run until after login.
71 quirks::QuirksManager::Get()->OnLoginCompleted();
72 }
73
74 // Query QuirksManager for icc file, then run msg loop to wait for callback. 59 // Query QuirksManager for icc file, then run msg loop to wait for callback.
75 // |find_fake_file| indicates that URLFetcher should respond with success. 60 // |find_fake_file| indicates that URLFetcher should respond with success.
76 void TestQuirksClient(int64_t product_id, bool find_fake_file) { 61 void TestQuirksClient(int64_t product_id, bool find_fake_file) {
77 // Set up fake url getter. 62 // Set up fake url getter.
78 QuirksManager::Get()->SetFakeQuirksFetcherCreatorForTests( 63 QuirksManager::Get()->SetFakeQuirksFetcherCreatorForTests(
79 base::Bind(find_fake_file ? &CreateFakeURLFetcherSuccess 64 base::Bind(find_fake_file ? &CreateFakeURLFetcherSuccess
80 : &CreateFakeURLFetcherFailure)); 65 : &CreateFakeURLFetcherFailure));
81 66
82 base::RunLoop run_loop; 67 base::RunLoop run_loop;
83 end_message_loop_ = run_loop.QuitClosure(); 68 end_message_loop_ = run_loop.QuitClosure();
(...skipping 11 matching lines...) Expand all
95 file_existed_ = !downloaded; 80 file_existed_ = !downloaded;
96 ASSERT_TRUE(!end_message_loop_.is_null()); 81 ASSERT_TRUE(!end_message_loop_.is_null());
97 end_message_loop_.Run(); 82 end_message_loop_.Run();
98 } 83 }
99 84
100 // InProcessBrowserTest overrides. 85 // InProcessBrowserTest overrides.
101 void SetUpCommandLine(base::CommandLine* command_line) override { 86 void SetUpCommandLine(base::CommandLine* command_line) override {
102 command_line->AppendSwitch(switches::kEnableQuirksClient); 87 command_line->AppendSwitch(switches::kEnableQuirksClient);
103 } 88 }
104 89
105 void SetUpOnMainThread() override { Initialize(); } 90 void SetUpOnMainThread() override {
91 // NOTE: QuirksManager::Initialize() isn't necessary here, since it'll be
92 // called in ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun().
93
94 // Create display_profiles subdirectory under temp profile directory.
95 const base::FilePath path =
96 QuirksManager::Get()->delegate()->GetDownloadDisplayProfileDirectory();
97 base::File::Error error = base::File::FILE_OK;
98 bool created = base::CreateDirectoryAndGetError(path, &error);
99 ASSERT_TRUE(created);
100
101 // Quirks clients can't run until after login.
102 quirks::QuirksManager::Get()->OnLoginCompleted();
103 }
106 104
107 base::Closure end_message_loop_; // Callback to terminate message loop. 105 base::Closure end_message_loop_; // Callback to terminate message loop.
108 base::FilePath icc_path_; // Path to icc file if found or downloaded. 106 base::FilePath icc_path_; // Path to icc file if found or downloaded.
109 bool file_existed_; // File was previously downloaded. 107 bool file_existed_; // File was previously downloaded.
110 108
111 private: 109 private:
112 DISALLOW_COPY_AND_ASSIGN(QuirksBrowserTest); 110 DISALLOW_COPY_AND_ASSIGN(QuirksBrowserTest);
113 }; 111 };
114 112
115 IN_PROC_BROWSER_TEST_F(QuirksBrowserTest, DownloadIccFile) { 113 IN_PROC_BROWSER_TEST_F(QuirksBrowserTest, DownloadIccFile) {
(...skipping 14 matching lines...) Expand all
130 EXPECT_EQ(file_existed_, true); 128 EXPECT_EQ(file_existed_, true);
131 129
132 // Finally, request a file that doesn't exist on fake Quirks Server. 130 // Finally, request a file that doesn't exist on fake Quirks Server.
133 TestQuirksClient(0x1111bbbb, false); 131 TestQuirksClient(0x1111bbbb, false);
134 EXPECT_EQ(icc_path_, base::FilePath()); 132 EXPECT_EQ(icc_path_, base::FilePath());
135 EXPECT_EQ(file_existed_, false); 133 EXPECT_EQ(file_existed_, false);
136 EXPECT_FALSE(base::PathExists(GetPathForIccFile(0x1111bbbb))); 134 EXPECT_FALSE(base::PathExists(GetPathForIccFile(0x1111bbbb)));
137 } 135 }
138 136
139 } // namespace quirks 137 } // namespace quirks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698