| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/global_error_service.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "chrome/browser/ui/browser.h" | |
| 9 #include "chrome/browser/ui/global_error.h" | |
| 10 #include "chrome/browser/ui/global_error_bubble_view_base.h" | |
| 11 #include "chrome/browser/ui/global_error_service_factory.h" | |
| 12 #include "chrome/test/base/in_process_browser_test.h" | |
| 13 #include "chrome/test/base/ui_test_utils.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // An error that has a bubble view. | |
| 18 class BubbleViewError : public GlobalError { | |
| 19 public: | |
| 20 BubbleViewError() : bubble_view_close_count_(0) { } | |
| 21 | |
| 22 int bubble_view_close_count() { return bubble_view_close_count_; } | |
| 23 | |
| 24 bool HasBadge() OVERRIDE { return false; } | |
| 25 virtual int GetBadgeResourceID() OVERRIDE { | |
| 26 ADD_FAILURE(); | |
| 27 return 0; | |
| 28 } | |
| 29 | |
| 30 virtual bool HasMenuItem() OVERRIDE { return false; } | |
| 31 virtual int MenuItemCommandID() OVERRIDE { | |
| 32 ADD_FAILURE(); | |
| 33 return 0; | |
| 34 } | |
| 35 virtual string16 MenuItemLabel() OVERRIDE { | |
| 36 ADD_FAILURE(); | |
| 37 return string16(); | |
| 38 } | |
| 39 virtual int MenuItemIconResourceID() OVERRIDE { | |
| 40 ADD_FAILURE(); | |
| 41 return 0; | |
| 42 } | |
| 43 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE { ADD_FAILURE(); } | |
| 44 | |
| 45 virtual bool HasBubbleView() OVERRIDE { return true; } | |
| 46 virtual string16 GetBubbleViewTitle() OVERRIDE { | |
| 47 return string16(); | |
| 48 } | |
| 49 virtual string16 GetBubbleViewMessage() OVERRIDE { | |
| 50 return string16(); | |
| 51 } | |
| 52 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE { | |
| 53 return string16(); | |
| 54 } | |
| 55 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE { | |
| 56 return string16(); | |
| 57 } | |
| 58 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE { | |
| 59 EXPECT_TRUE(browser); | |
| 60 ++bubble_view_close_count_; | |
| 61 } | |
| 62 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE {} | |
| 63 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE {} | |
| 64 | |
| 65 private: | |
| 66 int bubble_view_close_count_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(BubbleViewError); | |
| 69 }; | |
| 70 | |
| 71 } // namespace | |
| 72 | |
| 73 class GlobalErrorServiceBrowserTest : public InProcessBrowserTest { | |
| 74 }; | |
| 75 | |
| 76 // Test that showing a error with a bubble view works. | |
| 77 IN_PROC_BROWSER_TEST_F(GlobalErrorServiceBrowserTest, ShowBubbleView) { | |
| 78 // This will be deleted by the GlobalErrorService. | |
| 79 BubbleViewError* error = new BubbleViewError; | |
| 80 | |
| 81 GlobalErrorService* service = | |
| 82 GlobalErrorServiceFactory::GetForProfile(browser()->profile()); | |
| 83 service->AddGlobalError(error); | |
| 84 | |
| 85 EXPECT_EQ(error, service->GetFirstGlobalErrorWithBubbleView()); | |
| 86 EXPECT_FALSE(error->HasShownBubbleView()); | |
| 87 EXPECT_EQ(0, error->bubble_view_close_count()); | |
| 88 | |
| 89 // Creating a second browser window should show the bubble view. | |
| 90 CreateBrowser(browser()->profile()); | |
| 91 EXPECT_EQ(NULL, service->GetFirstGlobalErrorWithBubbleView()); | |
| 92 EXPECT_TRUE(error->HasShownBubbleView()); | |
| 93 EXPECT_EQ(0, error->bubble_view_close_count()); | |
| 94 } | |
| 95 | |
| 96 // Test that GlobalErrorBubbleViewBase::CloseBubbleView correctly closes the | |
| 97 // bubble view. | |
| 98 IN_PROC_BROWSER_TEST_F(GlobalErrorServiceBrowserTest, CloseBubbleView) { | |
| 99 // This will be deleted by the GlobalErrorService. | |
| 100 BubbleViewError* error = new BubbleViewError; | |
| 101 | |
| 102 GlobalErrorService* service = | |
| 103 GlobalErrorServiceFactory::GetForProfile(browser()->profile()); | |
| 104 service->AddGlobalError(error); | |
| 105 | |
| 106 EXPECT_EQ(error, service->GetFirstGlobalErrorWithBubbleView()); | |
| 107 EXPECT_FALSE(error->HasShownBubbleView()); | |
| 108 EXPECT_EQ(0, error->bubble_view_close_count()); | |
| 109 | |
| 110 // Creating a second browser window should show the bubble view. | |
| 111 CreateBrowser(browser()->profile()); | |
| 112 EXPECT_EQ(NULL, service->GetFirstGlobalErrorWithBubbleView()); | |
| 113 EXPECT_TRUE(error->HasShownBubbleView()); | |
| 114 EXPECT_EQ(0, error->bubble_view_close_count()); | |
| 115 | |
| 116 // Explicitly close the bubble view. | |
| 117 EXPECT_TRUE(error->GetBubbleView()); | |
| 118 error->GetBubbleView()->CloseBubbleView(); | |
| 119 ui_test_utils::RunAllPendingInMessageLoop(); | |
| 120 EXPECT_EQ(1, error->bubble_view_close_count()); | |
| 121 } | |
| 122 | |
| 123 // Test that bubble is silently dismissed if it is showing when the GlobalError | |
| 124 // instance is removed from the profile. | |
| 125 #if defined(OS_WIN) | |
| 126 #define MAYBE_BubbleViewDismissedOnRemove DISABLED_BubbleViewDismissedOnRemove | |
| 127 #else | |
| 128 #define MAYBE_BubbleViewDismissedOnRemove BubbleViewDismissedOnRemove | |
| 129 #endif | |
| 130 IN_PROC_BROWSER_TEST_F(GlobalErrorServiceBrowserTest, | |
| 131 MAYBE_BubbleViewDismissedOnRemove) { | |
| 132 scoped_ptr<BubbleViewError> error(new BubbleViewError); | |
| 133 | |
| 134 GlobalErrorService* service = | |
| 135 GlobalErrorServiceFactory::GetForProfile(browser()->profile()); | |
| 136 service->AddGlobalError(error.get()); | |
| 137 | |
| 138 EXPECT_EQ(error.get(), service->GetFirstGlobalErrorWithBubbleView()); | |
| 139 error->ShowBubbleView(browser()); | |
| 140 ui_test_utils::RunAllPendingInMessageLoop(); | |
| 141 EXPECT_TRUE(error->HasShownBubbleView()); | |
| 142 EXPECT_EQ(0, error->bubble_view_close_count()); | |
| 143 | |
| 144 // Removing |error| from profile should dismiss the bubble view without | |
| 145 // calling |error->BubbleViewDidClose|. | |
| 146 service->RemoveGlobalError(error.get()); | |
| 147 ui_test_utils::RunAllPendingInMessageLoop(); | |
| 148 EXPECT_EQ(1, error->bubble_view_close_count()); | |
| 149 // |error| is no longer owned by service and will be deleted. | |
| 150 } | |
| OLD | NEW |