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.
5 #include "base/command_line.h"
6 #include "base/path_service.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/browser_navigator.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/url_constants.h"
17 #include "chrome/grit/theme_resources.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chrome/test/base/test_launcher_utils.h"
20 #include "chrome/test/base/test_switches.h"
21 #include "chrome/test/base/ui_test_utils.h"
22 #include "components/infobars/core/confirm_infobar_delegate.h"
23 #include "components/infobars/core/infobar.h"
24 #include "content/public/browser/gpu_data_manager.h"
25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_types.h"
27 #include "content/public/common/content_paths.h"
28 #include "content/public/test/browser_test_utils.h"
29 #include "gpu/config/gpu_test_config.h"
30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/base/page_transition_types.h"
32 #include "ui/gl/gl_implementation.h"
36 void SimulateGPUCrash(Browser
* browser
) {
37 // None of the ui_test_utils entry points supports what we need to
38 // do here: navigate with the PAGE_TRANSITION_FROM_ADDRESS_BAR flag,
39 // without waiting for the navigation. It would be painful to change
40 // either of the NavigateToURL entry points to support these two
41 // constraints, so we use chrome::Navigate directly.
42 chrome::NavigateParams
params(
44 GURL(content::kChromeUIGpuCrashURL
),
45 ui::PageTransitionFromInt(
46 ui::PAGE_TRANSITION_TYPED
|
47 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR
));
48 params
.disposition
= NEW_BACKGROUND_TAB
;
49 chrome::Navigate(¶ms
);
54 class WebGLInfoBarTest
: public InProcessBrowserTest
{
56 void SetUpInProcessBrowserTestFixture() override
{
57 base::FilePath test_dir
;
58 ASSERT_TRUE(PathService::Get(content::DIR_TEST_DATA
, &test_dir
));
59 gpu_test_dir_
= test_dir
.AppendASCII("gpu");
61 base::FilePath gpu_test_dir_
;
64 // This test is flaky. http://crbug.com/324555
65 IN_PROC_BROWSER_TEST_F(WebGLInfoBarTest
, DISABLED_ContextLossRaisesInfoBar
) {
66 #undef MAYBE_ContextLossRaisesInfoBard
67 #if defined(OS_WIN) && defined(USE_ASH)
68 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
69 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
70 switches::kAshBrowserTests
))
74 if (gpu::GPUTestBotConfig::CurrentConfigMatches("XP"))
77 // Load page and wait for it to load.
78 content::WindowedNotificationObserver
observer(
79 content::NOTIFICATION_LOAD_STOP
,
80 content::NotificationService::AllSources());
81 ui_test_utils::NavigateToURL(
83 content::GetFileUrlWithQuery(
84 gpu_test_dir_
.AppendASCII("webgl.html"), "query=kill"));
87 content::WindowedNotificationObserver
infobar_added(
88 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED
,
89 content::NotificationService::AllSources());
90 SimulateGPUCrash(browser());
93 InfoBarService::FromWebContents(
94 browser()->tab_strip_model()->GetActiveWebContents())->
98 // This test is flaky. http://crbug.com/324555
99 IN_PROC_BROWSER_TEST_F(WebGLInfoBarTest
, DISABLED_ContextLossInfoBarReload
) {
100 #if defined(OS_WIN) && defined(USE_ASH)
101 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
102 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
103 switches::kAshBrowserTests
))
107 if (gpu::GPUTestBotConfig::CurrentConfigMatches("XP"))
110 content::DOMMessageQueue message_queue
;
112 // Load page and wait for it to load.
113 content::WindowedNotificationObserver
observer(
114 content::NOTIFICATION_LOAD_STOP
,
115 content::NotificationService::AllSources());
116 ui_test_utils::NavigateToURL(
118 content::GetFileUrlWithQuery(
119 gpu_test_dir_
.AppendASCII("webgl.html"),
120 "query=kill_after_notification"));
124 ASSERT_TRUE(message_queue
.WaitForMessage(&m
));
125 EXPECT_EQ("\"LOADED\"", m
);
127 message_queue
.ClearQueue();
129 content::WindowedNotificationObserver
infobar_added(
130 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED
,
131 content::NotificationService::AllSources());
132 SimulateGPUCrash(browser());
133 infobar_added
.Wait();
134 InfoBarService
* infobar_service
= InfoBarService::FromWebContents(
135 browser()->tab_strip_model()->GetActiveWebContents());
136 ASSERT_EQ(1u, infobar_service
->infobar_count());
137 infobars::InfoBarDelegate
* delegate
=
138 infobar_service
->infobar_at(0)->delegate();
139 ASSERT_EQ(IDR_INFOBAR_3D_BLOCKED
, delegate
->GetIconID());
140 delegate
->AsConfirmInfoBarDelegate()->Cancel();
142 // The page should reload and another message sent to the
143 // DomAutomationController.
145 ASSERT_TRUE(message_queue
.WaitForMessage(&m
));
146 EXPECT_EQ("\"LOADED\"", m
);
149 // There isn't any point in adding a test which calls Accept() on the
150 // ThreeDAPIInfoBarDelegate; doing so doesn't remove the infobar, and
151 // there's no concrete event that could be observed in response.