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

Side by Side Diff: chrome/browser/ui/webui/profile_helper_browsertest.cc

Issue 2802013002: Move BrowsingDataRemoverImpl:: CompletionInhibitor to the public interface (Closed)
Patch Set: Fix profile tests. Created 3 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/memory/ptr_util.h" 5 #include "base/memory/ptr_util.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/scoped_observer.h" 7 #include "base/scoped_observer.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" 9 #include "chrome/browser/browsing_data/browsing_data_remover.h"
10 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
11 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
10 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/profiles/profile_attributes_storage.h" 13 #include "chrome/browser/profiles/profile_attributes_storage.h"
12 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/browser_list_observer.h" 17 #include "chrome/browser/ui/browser_list_observer.h"
16 #include "chrome/browser/ui/webui/profile_helper.h" 18 #include "chrome/browser/ui/webui/profile_helper.h"
17 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
18 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
19 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 if (browser->profile() == profile_) 61 if (browser->profile() == profile_)
60 loop_.Quit(); 62 loop_.Quit();
61 } 63 }
62 64
63 private: 65 private:
64 Profile* profile_; 66 Profile* profile_;
65 base::RunLoop loop_; 67 base::RunLoop loop_;
66 ScopedObserver<BrowserList, chrome::BrowserListObserver> scoped_observer_; 68 ScopedObserver<BrowserList, chrome::BrowserListObserver> scoped_observer_;
67 }; 69 };
68 70
69 // TODO(bug 704601): remove it when bug is fixed.
70 class BrowsingDataRemoverObserver
71 : public BrowsingDataRemoverImpl::CompletionInhibitor {
72 public:
73 explicit BrowsingDataRemoverObserver(const base::Closure& callback)
74 : callback_(callback) {
75 BrowsingDataRemoverImpl::set_completion_inhibitor_for_testing(this);
76 }
77 ~BrowsingDataRemoverObserver() override {
78 BrowsingDataRemoverImpl::set_completion_inhibitor_for_testing(nullptr);
79 }
80
81 private:
82 void OnBrowsingDataRemoverWouldComplete(
83 BrowsingDataRemoverImpl* remover,
84 const base::Closure& continue_to_completion) override {
85 continue_to_completion.Run();
86 callback_.Run();
87 }
88
89 const base::Closure callback_;
90 };
91
92 } // namespace 71 } // namespace
93 72
94 using ProfileHelperTest = InProcessBrowserTest; 73 using ProfileHelperTest = InProcessBrowserTest;
95 74
96 IN_PROC_BROWSER_TEST_F(ProfileHelperTest, OpenNewWindowForProfile) { 75 IN_PROC_BROWSER_TEST_F(ProfileHelperTest, OpenNewWindowForProfile) {
97 BrowserList* browser_list = BrowserList::GetInstance(); 76 BrowserList* browser_list = BrowserList::GetInstance();
98 77
99 Browser* original_browser = browser(); 78 Browser* original_browser = browser();
100 Profile* original_profile = original_browser->profile(); 79 Profile* original_profile = original_browser->profile();
101 std::unique_ptr<ExpectBrowserActivationForProfile> activation_observer; 80 std::unique_ptr<ExpectBrowserActivationForProfile> activation_observer;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 177 g_browser_process->profile_manager()->GetProfileAttributesStorage();
199 178
200 BrowserList* browser_list = BrowserList::GetInstance(); 179 BrowserList* browser_list = BrowserList::GetInstance();
201 EXPECT_EQ(1u, browser_list->size()); 180 EXPECT_EQ(1u, browser_list->size());
202 EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser)); 181 EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser));
203 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); 182 EXPECT_EQ(1u, storage.GetNumberOfProfiles());
204 183
205 Profile* additional_profile = CreateProfile(); 184 Profile* additional_profile = CreateProfile();
206 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); 185 EXPECT_EQ(2u, storage.GetNumberOfProfiles());
207 186
208 base::RunLoop loop; 187 BrowsingDataRemoverCompletionInhibitor inhibitor(
209 BrowsingDataRemoverObserver observer(loop.QuitClosure()); 188 BrowsingDataRemoverFactory::GetForBrowserContext(additional_profile));
210 webui::DeleteProfileAtPath(additional_profile->GetPath(), &web_ui, 189 webui::DeleteProfileAtPath(additional_profile->GetPath(), &web_ui,
211 ProfileMetrics::DELETE_PROFILE_SETTINGS); 190 ProfileMetrics::DELETE_PROFILE_SETTINGS);
212 loop.Run(); 191 inhibitor.BlockUntilNearCompletion();
msramek 2017/04/10 13:20:08 This test was just reinventing BlockUntilNearCompl
192 inhibitor.ContinueToCompletion();
213 193
214 EXPECT_EQ(1u, browser_list->size()); 194 EXPECT_EQ(1u, browser_list->size());
215 EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser)); 195 EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser));
216 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); 196 EXPECT_EQ(1u, storage.GetNumberOfProfiles());
217 } 197 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698