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

Side by Side Diff: chrome/browser/ui/global_error/global_error_service_browsertest.cc

Issue 2409443002: Make GlobalErrorService's ownership model slightly less insane. (Closed)
Patch Set: deprecation notice Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/global_error/global_error_service.h" 5 #include "chrome/browser/ui/global_error/global_error_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h"
10 #include "build/build_config.h" 11 #include "build/build_config.h"
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/global_error/global_error.h" 13 #include "chrome/browser/ui/global_error/global_error.h"
13 #include "chrome/browser/ui/global_error/global_error_bubble_view_base.h" 14 #include "chrome/browser/ui/global_error/global_error_bubble_view_base.h"
14 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 15 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
15 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
16 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
17 18
18 namespace { 19 namespace {
19 20
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 class GlobalErrorServiceBrowserTest : public InProcessBrowserTest { 65 class GlobalErrorServiceBrowserTest : public InProcessBrowserTest {
65 }; 66 };
66 67
67 // Test that showing a error with a bubble view works. 68 // Test that showing a error with a bubble view works.
68 IN_PROC_BROWSER_TEST_F(GlobalErrorServiceBrowserTest, ShowBubbleView) { 69 IN_PROC_BROWSER_TEST_F(GlobalErrorServiceBrowserTest, ShowBubbleView) {
69 // This will be deleted by the GlobalErrorService. 70 // This will be deleted by the GlobalErrorService.
70 BubbleViewError* error = new BubbleViewError; 71 BubbleViewError* error = new BubbleViewError;
71 72
72 GlobalErrorService* service = 73 GlobalErrorService* service =
73 GlobalErrorServiceFactory::GetForProfile(browser()->profile()); 74 GlobalErrorServiceFactory::GetForProfile(browser()->profile());
74 service->AddGlobalError(error); 75 service->AddGlobalError(base::WrapUnique(error));
75 76
76 EXPECT_EQ(error, service->GetFirstGlobalErrorWithBubbleView()); 77 EXPECT_EQ(error, service->GetFirstGlobalErrorWithBubbleView());
77 EXPECT_FALSE(error->HasShownBubbleView()); 78 EXPECT_FALSE(error->HasShownBubbleView());
78 EXPECT_EQ(0, error->bubble_view_close_count()); 79 EXPECT_EQ(0, error->bubble_view_close_count());
79 80
80 // Creating a second browser window should show the bubble view. 81 // Creating a second browser window should show the bubble view.
81 CreateBrowser(browser()->profile()); 82 CreateBrowser(browser()->profile());
82 EXPECT_EQ(NULL, service->GetFirstGlobalErrorWithBubbleView()); 83 EXPECT_EQ(NULL, service->GetFirstGlobalErrorWithBubbleView());
83 EXPECT_TRUE(error->HasShownBubbleView()); 84 EXPECT_TRUE(error->HasShownBubbleView());
84 EXPECT_EQ(0, error->bubble_view_close_count()); 85 EXPECT_EQ(0, error->bubble_view_close_count());
85 } 86 }
86 87
87 // Test that GlobalErrorBubbleViewBase::CloseBubbleView correctly closes the 88 // Test that GlobalErrorBubbleViewBase::CloseBubbleView correctly closes the
88 // bubble view. 89 // bubble view.
89 IN_PROC_BROWSER_TEST_F(GlobalErrorServiceBrowserTest, CloseBubbleView) { 90 IN_PROC_BROWSER_TEST_F(GlobalErrorServiceBrowserTest, CloseBubbleView) {
90 // This will be deleted by the GlobalErrorService. 91 // This will be deleted by the GlobalErrorService.
91 BubbleViewError* error = new BubbleViewError; 92 BubbleViewError* error = new BubbleViewError;
92 93
93 GlobalErrorService* service = 94 GlobalErrorService* service =
94 GlobalErrorServiceFactory::GetForProfile(browser()->profile()); 95 GlobalErrorServiceFactory::GetForProfile(browser()->profile());
95 service->AddGlobalError(error); 96 service->AddGlobalError(base::WrapUnique(error));
96 97
97 EXPECT_EQ(error, service->GetFirstGlobalErrorWithBubbleView()); 98 EXPECT_EQ(error, service->GetFirstGlobalErrorWithBubbleView());
98 EXPECT_FALSE(error->HasShownBubbleView()); 99 EXPECT_FALSE(error->HasShownBubbleView());
99 EXPECT_EQ(0, error->bubble_view_close_count()); 100 EXPECT_EQ(0, error->bubble_view_close_count());
100 101
101 // Creating a second browser window should show the bubble view. 102 // Creating a second browser window should show the bubble view.
102 CreateBrowser(browser()->profile()); 103 CreateBrowser(browser()->profile());
103 EXPECT_EQ(NULL, service->GetFirstGlobalErrorWithBubbleView()); 104 EXPECT_EQ(NULL, service->GetFirstGlobalErrorWithBubbleView());
104 EXPECT_TRUE(error->HasShownBubbleView()); 105 EXPECT_TRUE(error->HasShownBubbleView());
105 EXPECT_EQ(0, error->bubble_view_close_count()); 106 EXPECT_EQ(0, error->bubble_view_close_count());
106 107
107 // Explicitly close the bubble view. 108 // Explicitly close the bubble view.
108 EXPECT_TRUE(error->GetBubbleView()); 109 EXPECT_TRUE(error->GetBubbleView());
109 error->GetBubbleView()->CloseBubbleView(); 110 error->GetBubbleView()->CloseBubbleView();
110 content::RunAllPendingInMessageLoop(); 111 content::RunAllPendingInMessageLoop();
111 EXPECT_EQ(1, error->bubble_view_close_count()); 112 EXPECT_EQ(1, error->bubble_view_close_count());
112 } 113 }
113 114
114 // Test that bubble is silently dismissed if it is showing when the GlobalError 115 // Test that bubble is silently dismissed if it is showing when the GlobalError
115 // instance is removed from the profile. 116 // instance is removed from the profile.
116 #if defined(OS_WIN) || defined(OS_LINUX) 117 #if defined(OS_WIN) || defined(OS_LINUX)
117 // http://crbug.com/396473 118 // http://crbug.com/396473
118 #define MAYBE_BubbleViewDismissedOnRemove DISABLED_BubbleViewDismissedOnRemove 119 #define MAYBE_BubbleViewDismissedOnRemove DISABLED_BubbleViewDismissedOnRemove
119 #else 120 #else
120 #define MAYBE_BubbleViewDismissedOnRemove BubbleViewDismissedOnRemove 121 #define MAYBE_BubbleViewDismissedOnRemove BubbleViewDismissedOnRemove
121 #endif 122 #endif
122 IN_PROC_BROWSER_TEST_F(GlobalErrorServiceBrowserTest, 123 IN_PROC_BROWSER_TEST_F(GlobalErrorServiceBrowserTest,
123 MAYBE_BubbleViewDismissedOnRemove) { 124 MAYBE_BubbleViewDismissedOnRemove) {
124 std::unique_ptr<BubbleViewError> error(new BubbleViewError); 125 std::unique_ptr<BubbleViewError> error(new BubbleViewError);
Nico 2016/12/13 15:54:14 Does this one have to be unowned? Or did you leave
Avi (use Gerrit) 2016/12/13 16:06:00 I'll pretend this was the latter :) Adding a comme
125 126
126 GlobalErrorService* service = 127 GlobalErrorService* service =
127 GlobalErrorServiceFactory::GetForProfile(browser()->profile()); 128 GlobalErrorServiceFactory::GetForProfile(browser()->profile());
128 service->AddGlobalError(error.get()); 129 service->AddUnownedGlobalError(error.get());
129 130
130 EXPECT_EQ(error.get(), service->GetFirstGlobalErrorWithBubbleView()); 131 EXPECT_EQ(error.get(), service->GetFirstGlobalErrorWithBubbleView());
131 error->ShowBubbleView(browser()); 132 error->ShowBubbleView(browser());
132 content::RunAllPendingInMessageLoop(); 133 content::RunAllPendingInMessageLoop();
133 EXPECT_TRUE(error->HasShownBubbleView()); 134 EXPECT_TRUE(error->HasShownBubbleView());
134 EXPECT_EQ(0, error->bubble_view_close_count()); 135 EXPECT_EQ(0, error->bubble_view_close_count());
135 136
136 // Removing |error| from profile should dismiss the bubble view without 137 // Removing |error| from profile should dismiss the bubble view without
137 // calling |error->BubbleViewDidClose|. 138 // calling |error->BubbleViewDidClose|.
138 service->RemoveGlobalError(error.get()); 139 service->RemoveUnownedGlobalError(error.get());
139 content::RunAllPendingInMessageLoop(); 140 content::RunAllPendingInMessageLoop();
140 EXPECT_EQ(1, error->bubble_view_close_count()); 141 EXPECT_EQ(1, error->bubble_view_close_count());
141 // |error| is no longer owned by service and will be deleted.
142 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698