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

Side by Side Diff: chrome/browser/ui/chrome_bubble_manager_unittest.cc

Issue 1572743002: Make sure bubbles in Views default to close before their RenderFrameHosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Move DCHECK string into longer comment Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/chrome_bubble_manager.h" 5 #include "chrome/browser/ui/chrome_bubble_manager.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" 8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" 9 #include "chrome/test/base/browser_with_test_window_test.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "components/bubble/bubble_controller.h" 10 #include "components/bubble/bubble_controller.h"
12 #include "components/bubble/bubble_manager_mocks.h" 11 #include "components/bubble/bubble_manager_mocks.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 12 #include "content/public/browser/web_contents.h"
13 #include "content/public/test/test_renderer_host.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace { 16 namespace {
17 17
18 class ChromeBubbleManagerTest : public testing::Test { 18 class ChromeBubbleManagerTest : public BrowserWithTestWindowTest {
19 public: 19 public:
20 ChromeBubbleManagerTest(); 20 ChromeBubbleManagerTest() {}
21 ~ChromeBubbleManagerTest() override;
22 21
23 // testing::Test: 22 // testing::Test:
24 void SetUp() override; 23 void SetUp() override;
25 void TearDown() override; 24 void TearDown() override;
26 25
27 protected: 26 protected:
28 scoped_ptr<TestingProfile> profile_;
29 scoped_ptr<TestTabStripModelDelegate> delegate_;
30 scoped_ptr<TabStripModel> tabstrip_;
31 scoped_ptr<ChromeBubbleManager> manager_; 27 scoped_ptr<ChromeBubbleManager> manager_;
32 28
33 private: 29 private:
34 // ChromeBubbleManager expects to be on the UI thread.
35 content::TestBrowserThreadBundle thread_bundle_;
36
37 DISALLOW_COPY_AND_ASSIGN(ChromeBubbleManagerTest); 30 DISALLOW_COPY_AND_ASSIGN(ChromeBubbleManagerTest);
38 }; 31 };
39 32
40 ChromeBubbleManagerTest::ChromeBubbleManagerTest()
41 : thread_bundle_(content::TestBrowserThreadBundle::DEFAULT) {}
42
43 ChromeBubbleManagerTest::~ChromeBubbleManagerTest() {}
44
45 void ChromeBubbleManagerTest::SetUp() { 33 void ChromeBubbleManagerTest::SetUp() {
46 testing::Test::SetUp(); 34 BrowserWithTestWindowTest::SetUp();
47 35 manager_.reset(new ChromeBubbleManager(browser()->tab_strip_model()));
48 profile_.reset(new TestingProfile);
49 delegate_.reset(new TestTabStripModelDelegate);
50 tabstrip_.reset(new TabStripModel(delegate_.get(), profile_.get()));
51 manager_.reset(new ChromeBubbleManager(tabstrip_.get()));
52 } 36 }
53 37
54 void ChromeBubbleManagerTest::TearDown() { 38 void ChromeBubbleManagerTest::TearDown() {
55 manager_.reset(); 39 manager_.reset();
56 tabstrip_.reset(); 40 BrowserWithTestWindowTest::TearDown();
57 delegate_.reset();
58 profile_.reset();
59 testing::Test::TearDown();
60 } 41 }
61 42
62 TEST_F(ChromeBubbleManagerTest, CloseMockBubbleOnDestroy) { 43 TEST_F(ChromeBubbleManagerTest, CloseMockBubbleOnDestroy) {
63 BubbleReference bubble1 = manager_->ShowBubble(MockBubbleDelegate::Default()); 44 BubbleReference bubble1 = manager_->ShowBubble(MockBubbleDelegate::Default());
64 manager_.reset(); 45 manager_.reset();
65 ASSERT_FALSE(bubble1); 46 ASSERT_FALSE(bubble1);
66 } 47 }
67 48
68 TEST_F(ChromeBubbleManagerTest, CloseMockBubbleForTwoDifferentReasons) { 49 TEST_F(ChromeBubbleManagerTest, CloseMockBubbleForTwoDifferentReasons) {
69 BubbleReference bubble1 = manager_->ShowBubble(MockBubbleDelegate::Default()); 50 BubbleReference bubble1 = manager_->ShowBubble(MockBubbleDelegate::Default());
70 BubbleReference bubble2 = manager_->ShowBubble(MockBubbleDelegate::Default()); 51 BubbleReference bubble2 = manager_->ShowBubble(MockBubbleDelegate::Default());
71 52
72 bubble1->CloseBubble(BUBBLE_CLOSE_ACCEPTED); 53 bubble1->CloseBubble(BUBBLE_CLOSE_ACCEPTED);
73 bubble2->CloseBubble(BUBBLE_CLOSE_CANCELED); 54 bubble2->CloseBubble(BUBBLE_CLOSE_CANCELED);
74 55
75 ASSERT_FALSE(bubble1); 56 ASSERT_FALSE(bubble1);
76 ASSERT_FALSE(bubble2); 57 ASSERT_FALSE(bubble2);
77 } 58 }
78 59
60 TEST_F(ChromeBubbleManagerTest, CloseMockBubbleOnNavigate) {
61 AddTab(browser(), GURL("https://foo/0"));
62
63 scoped_ptr<MockBubbleDelegate> delegate(new MockBubbleDelegate);
64 EXPECT_CALL(*delegate, ShouldClose(BUBBLE_CLOSE_NAVIGATED))
65 .WillOnce(testing::Return(true));
66 EXPECT_CALL(*delegate, DidClose());
67 EXPECT_CALL(*delegate, Destroyed());
68
69 BubbleReference bubble_ref = manager_->ShowBubble(std::move(delegate));
70
71 NavigateAndCommitActiveTab(GURL("https://foo/1"));
72
73 ASSERT_FALSE(bubble_ref);
74 }
75
76 TEST_F(ChromeBubbleManagerTest, CloseMockBubbleOnOwningFrameDestroy) {
77 AddTab(browser(), GURL("https://foo/0"));
78
79 content::RenderFrameHostTester* main_frame =
80 content::RenderFrameHostTester::For(
81 browser()->tab_strip_model()->GetWebContentsAt(0)->GetMainFrame());
82
83 content::RenderFrameHost* subframe0 = main_frame->AppendChild("subframe0");
84 content::RenderFrameHostTester* subframe0_tester =
85 content::RenderFrameHostTester::For(subframe0);
86
87 content::RenderFrameHost* subframe1 = main_frame->AppendChild("subframe1");
88 content::RenderFrameHostTester* subframe1_tester =
89 content::RenderFrameHostTester::For(subframe1);
90
91 scoped_ptr<MockBubbleDelegate> delegate(new MockBubbleDelegate);
92 EXPECT_CALL(*delegate, OwningFrame())
93 .WillRepeatedly(testing::Return(subframe0));
94 EXPECT_CALL(*delegate, ShouldClose(BUBBLE_CLOSE_FRAME_DESTROYED))
95 .WillOnce(testing::Return(true));
96 EXPECT_CALL(*delegate, DidClose());
97 EXPECT_CALL(*delegate, Destroyed());
98
99 BubbleReference bubble_ref = manager_->ShowBubble(std::move(delegate));
100
101 subframe1_tester->Detach();
102 EXPECT_TRUE(bubble_ref) << "The bubble shouldn't be destroyed when a "
103 "non-owning frame is destroyed.";
104
105 subframe0_tester->Detach();
106 EXPECT_FALSE(bubble_ref);
107 }
108
79 } // namespace 109 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/chrome_bubble_manager.cc ('k') | chrome/browser/ui/extensions/extension_installed_bubble.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698