1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
#include "base/command_line.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/website_settings/mock_permission_bubble_factory.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
namespace {
class PermissionBubbleManagerBrowserTest : public InProcessBrowserTest {
public:
PermissionBubbleManagerBrowserTest() = default;
~PermissionBubbleManagerBrowserTest() override = default;
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
PermissionBubbleManager* manager = GetPermissionBubbleManager();
mock_permission_bubble_factory_.reset(
new MockPermissionBubbleFactory(true, manager));
manager->DisplayPendingRequests();
}
void TearDownOnMainThread() override {
mock_permission_bubble_factory_.reset();
InProcessBrowserTest::TearDownOnMainThread();
}
PermissionBubbleManager* GetPermissionBubbleManager() {
return PermissionBubbleManager::FromWebContents(
browser()->tab_strip_model()->GetActiveWebContents());
}
void WaitForPermissionBubble() {
if (bubble_factory()->is_visible())
return;
content::RunMessageLoop();
}
MockPermissionBubbleFactory* bubble_factory() {
return mock_permission_bubble_factory_.get();
}
private:
scoped_ptr<MockPermissionBubbleFactory> mock_permission_bubble_factory_;
};
// Requests before the load event should be bundled into one bubble.
// http://crbug.com/512849 flaky
IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest,
DISABLED_RequestsBeforeLoad) {
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(),
embedded_test_server()->GetURL("/permissions/requests-before-load.html"),
1);
WaitForPermissionBubble();
EXPECT_EQ(1, bubble_factory()->show_count());
EXPECT_EQ(2, bubble_factory()->total_request_count());
}
// Requests before the load should not be bundled with a request after the load.
IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest,
RequestsBeforeAfterLoad) {
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(),
embedded_test_server()->GetURL(
"/permissions/requests-before-after-load.html"),
1);
WaitForPermissionBubble();
EXPECT_EQ(1, bubble_factory()->show_count());
EXPECT_EQ(1, bubble_factory()->total_request_count());
}
// Navigating twice to the same URL should be equivalent to refresh. This means
// showing the bubbles twice.
// http://crbug.com/512849 flaky
#if defined(OS_WIN)
#define MAYBE_NavTwice DISABLED_NavTwice
#else
#define MAYBE_NavTwice NavTwice
#endif
IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest, MAYBE_NavTwice) {
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(),
embedded_test_server()->GetURL("/permissions/requests-before-load.html"),
1);
WaitForPermissionBubble();
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(),
embedded_test_server()->GetURL("/permissions/requests-before-load.html"),
1);
WaitForPermissionBubble();
EXPECT_EQ(2, bubble_factory()->show_count());
EXPECT_EQ(4, bubble_factory()->total_request_count());
}
// Navigating twice to the same URL with a hash should be navigation within the
// page. This means the bubble is only shown once.
// http://crbug.com/512849 flaky
#if defined(OS_WIN)
#define MAYBE_NavTwiceWithHash DISABLED_NavTwiceWithHash
#else
#define MAYBE_NavTwiceWithHash NavTwiceWithHash
#endif
IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest,
MAYBE_NavTwiceWithHash) {
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(),
embedded_test_server()->GetURL("/permissions/requests-before-load.html"),
1);
WaitForPermissionBubble();
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(),
embedded_test_server()->GetURL(
"/permissions/requests-before-load.html#0"),
1);
WaitForPermissionBubble();
EXPECT_EQ(1, bubble_factory()->show_count());
EXPECT_EQ(2, bubble_factory()->total_request_count());
}
// Bubble requests should be shown after in-page navigation.
IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest, InPageNavigation) {
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(),
embedded_test_server()->GetURL("/empty.html"),
1);
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
browser(),
embedded_test_server()->GetURL("/empty.html#0"),
1);
// Request 'geolocation' permission.
ExecuteScriptAndGetValue(
browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
"navigator.geolocation.getCurrentPosition(function(){});");
WaitForPermissionBubble();
EXPECT_EQ(1, bubble_factory()->show_count());
EXPECT_EQ(1, bubble_factory()->total_request_count());
}
} // anonymous namespace
|