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 "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/confirm_infobar_delegate.h"
10 #include "chrome/browser/infobars/infobar.h"
11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_commands.h"
14 #include "chrome/browser/ui/browser_navigator.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/test_launcher_utils.h"
21 #include "chrome/test/base/test_switches.h"
22 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/public/browser/gpu_data_manager.h"
24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/notification_types.h"
26 #include "content/public/common/content_paths.h"
27 #include "content/public/common/page_transition_types.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/gl/gl_implementation.h"
32
33 namespace {
34
SimulateGPUCrash(Browser * browser)35 void SimulateGPUCrash(Browser* browser) {
36 // None of the ui_test_utils entry points supports what we need to
37 // do here: navigate with the PAGE_TRANSITION_FROM_ADDRESS_BAR flag,
38 // without waiting for the navigation. It would be painful to change
39 // either of the NavigateToURL entry points to support these two
40 // constraints, so we use chrome::Navigate directly.
41 chrome::NavigateParams params(
42 browser,
43 GURL(content::kChromeUIGpuCrashURL),
44 static_cast<content::PageTransition>(
45 content::PAGE_TRANSITION_TYPED |
46 content::PAGE_TRANSITION_FROM_ADDRESS_BAR));
47 params.disposition = NEW_BACKGROUND_TAB;
48 chrome::Navigate(¶ms);
49 }
50
51 } // namespace
52
53 class WebGLInfoBarTest : public InProcessBrowserTest {
54 protected:
SetUpInProcessBrowserTestFixture()55 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
56 base::FilePath test_dir;
57 ASSERT_TRUE(PathService::Get(content::DIR_TEST_DATA, &test_dir));
58 gpu_test_dir_ = test_dir.AppendASCII("gpu");
59 }
60 base::FilePath gpu_test_dir_;
61 };
62
63 // This test is flaky. http://crbug.com/324555
IN_PROC_BROWSER_TEST_F(WebGLInfoBarTest,DISABLED_ContextLossRaisesInfoBar)64 IN_PROC_BROWSER_TEST_F(WebGLInfoBarTest, DISABLED_ContextLossRaisesInfoBar) {
65 #undef MAYBE_ContextLossRaisesInfoBard
66 #if defined(OS_WIN) && defined(USE_ASH)
67 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
68 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
69 return;
70 #endif
71
72 if (gpu::GPUTestBotConfig::CurrentConfigMatches("XP"))
73 return;
74
75 // Load page and wait for it to load.
76 content::WindowedNotificationObserver observer(
77 content::NOTIFICATION_LOAD_STOP,
78 content::NotificationService::AllSources());
79 ui_test_utils::NavigateToURL(
80 browser(),
81 content::GetFileUrlWithQuery(
82 gpu_test_dir_.AppendASCII("webgl.html"), "query=kill"));
83 observer.Wait();
84
85 content::WindowedNotificationObserver infobar_added(
86 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
87 content::NotificationService::AllSources());
88 SimulateGPUCrash(browser());
89 infobar_added.Wait();
90 EXPECT_EQ(1u,
91 InfoBarService::FromWebContents(
92 browser()->tab_strip_model()->GetActiveWebContents())->
93 infobar_count());
94 }
95
96 // This test is flaky. http://crbug.com/324555
IN_PROC_BROWSER_TEST_F(WebGLInfoBarTest,DISABLED_ContextLossInfoBarReload)97 IN_PROC_BROWSER_TEST_F(WebGLInfoBarTest, DISABLED_ContextLossInfoBarReload) {
98 #if defined(OS_WIN) && defined(USE_ASH)
99 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
100 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
101 return;
102 #endif
103
104 if (gpu::GPUTestBotConfig::CurrentConfigMatches("XP"))
105 return;
106
107 content::DOMMessageQueue message_queue;
108
109 // Load page and wait for it to load.
110 content::WindowedNotificationObserver observer(
111 content::NOTIFICATION_LOAD_STOP,
112 content::NotificationService::AllSources());
113 ui_test_utils::NavigateToURL(
114 browser(),
115 content::GetFileUrlWithQuery(
116 gpu_test_dir_.AppendASCII("webgl.html"),
117 "query=kill_after_notification"));
118 observer.Wait();
119
120 std::string m;
121 ASSERT_TRUE(message_queue.WaitForMessage(&m));
122 EXPECT_EQ("\"LOADED\"", m);
123
124 message_queue.ClearQueue();
125
126 content::WindowedNotificationObserver infobar_added(
127 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
128 content::NotificationService::AllSources());
129 SimulateGPUCrash(browser());
130 infobar_added.Wait();
131 InfoBarService* infobar_service = InfoBarService::FromWebContents(
132 browser()->tab_strip_model()->GetActiveWebContents());
133 ASSERT_EQ(1u, infobar_service->infobar_count());
134 InfoBarDelegate* delegate = infobar_service->infobar_at(0)->delegate();
135 ASSERT_TRUE(delegate->AsThreeDAPIInfoBarDelegate());
136 delegate->AsConfirmInfoBarDelegate()->Cancel();
137
138 // The page should reload and another message sent to the
139 // DomAutomationController.
140 m.clear();
141 ASSERT_TRUE(message_queue.WaitForMessage(&m));
142 EXPECT_EQ("\"LOADED\"", m);
143 }
144
145 // There isn't any point in adding a test which calls Accept() on the
146 // ThreeDAPIInfoBarDelegate; doing so doesn't remove the infobar, and
147 // there's no concrete event that could be observed in response.
148