| OLD | NEW |
| 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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/global_error/global_error.h" | 9 #include "chrome/browser/ui/global_error/global_error.h" |
| 10 #include "chrome/browser/ui/global_error/global_error_bubble_view_base.h" | 10 #include "chrome/browser/ui/global_error/global_error_bubble_view_base.h" |
| 11 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 11 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // An error that has a bubble view. | 17 // An error that has a bubble view. |
| 18 class BubbleViewError : public GlobalErrorWithStandardBubble { | 18 class BubbleViewError : public GlobalErrorWithStandardBubble { |
| 19 public: | 19 public: |
| 20 BubbleViewError() : bubble_view_close_count_(0) { } | 20 BubbleViewError() : bubble_view_close_count_(0) { } |
| 21 | 21 |
| 22 int bubble_view_close_count() { return bubble_view_close_count_; } | 22 int bubble_view_close_count() { return bubble_view_close_count_; } |
| 23 | 23 |
| 24 virtual bool HasMenuItem() override { return false; } | 24 bool HasMenuItem() override { return false; } |
| 25 virtual int MenuItemCommandID() override { | 25 int MenuItemCommandID() override { |
| 26 ADD_FAILURE(); | 26 ADD_FAILURE(); |
| 27 return 0; | 27 return 0; |
| 28 } | 28 } |
| 29 virtual base::string16 MenuItemLabel() override { | 29 base::string16 MenuItemLabel() override { |
| 30 ADD_FAILURE(); | 30 ADD_FAILURE(); |
| 31 return base::string16(); | 31 return base::string16(); |
| 32 } | 32 } |
| 33 virtual void ExecuteMenuItem(Browser* browser) override { ADD_FAILURE(); } | 33 void ExecuteMenuItem(Browser* browser) override { ADD_FAILURE(); } |
| 34 | 34 |
| 35 virtual bool HasBubbleView() override { return true; } | 35 bool HasBubbleView() override { return true; } |
| 36 virtual base::string16 GetBubbleViewTitle() override { | 36 base::string16 GetBubbleViewTitle() override { return base::string16(); } |
| 37 std::vector<base::string16> GetBubbleViewMessages() override { |
| 38 return std::vector<base::string16>(); |
| 39 } |
| 40 base::string16 GetBubbleViewAcceptButtonLabel() override { |
| 37 return base::string16(); | 41 return base::string16(); |
| 38 } | 42 } |
| 39 virtual std::vector<base::string16> GetBubbleViewMessages() override { | 43 base::string16 GetBubbleViewCancelButtonLabel() override { |
| 40 return std::vector<base::string16>(); | |
| 41 } | |
| 42 virtual base::string16 GetBubbleViewAcceptButtonLabel() override { | |
| 43 return base::string16(); | 44 return base::string16(); |
| 44 } | 45 } |
| 45 virtual base::string16 GetBubbleViewCancelButtonLabel() override { | 46 void OnBubbleViewDidClose(Browser* browser) override { |
| 46 return base::string16(); | |
| 47 } | |
| 48 virtual void OnBubbleViewDidClose(Browser* browser) override { | |
| 49 EXPECT_TRUE(browser); | 47 EXPECT_TRUE(browser); |
| 50 ++bubble_view_close_count_; | 48 ++bubble_view_close_count_; |
| 51 } | 49 } |
| 52 virtual void BubbleViewAcceptButtonPressed(Browser* browser) override {} | 50 void BubbleViewAcceptButtonPressed(Browser* browser) override {} |
| 53 virtual void BubbleViewCancelButtonPressed(Browser* browser) override {} | 51 void BubbleViewCancelButtonPressed(Browser* browser) override {} |
| 54 | 52 |
| 55 private: | 53 private: |
| 56 int bubble_view_close_count_; | 54 int bubble_view_close_count_; |
| 57 | 55 |
| 58 DISALLOW_COPY_AND_ASSIGN(BubbleViewError); | 56 DISALLOW_COPY_AND_ASSIGN(BubbleViewError); |
| 59 }; | 57 }; |
| 60 | 58 |
| 61 } // namespace | 59 } // namespace |
| 62 | 60 |
| 63 class GlobalErrorServiceBrowserTest : public InProcessBrowserTest { | 61 class GlobalErrorServiceBrowserTest : public InProcessBrowserTest { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 EXPECT_TRUE(error->HasShownBubbleView()); | 130 EXPECT_TRUE(error->HasShownBubbleView()); |
| 133 EXPECT_EQ(0, error->bubble_view_close_count()); | 131 EXPECT_EQ(0, error->bubble_view_close_count()); |
| 134 | 132 |
| 135 // Removing |error| from profile should dismiss the bubble view without | 133 // Removing |error| from profile should dismiss the bubble view without |
| 136 // calling |error->BubbleViewDidClose|. | 134 // calling |error->BubbleViewDidClose|. |
| 137 service->RemoveGlobalError(error.get()); | 135 service->RemoveGlobalError(error.get()); |
| 138 content::RunAllPendingInMessageLoop(); | 136 content::RunAllPendingInMessageLoop(); |
| 139 EXPECT_EQ(1, error->bubble_view_close_count()); | 137 EXPECT_EQ(1, error->bubble_view_close_count()); |
| 140 // |error| is no longer owned by service and will be deleted. | 138 // |error| is no longer owned by service and will be deleted. |
| 141 } | 139 } |
| OLD | NEW |