chromeos: bluetooth: tie Proxy lifetime to object, not observer
[chromium-blink-merge.git] / chrome / browser / tab_first_render_watcher_browsertest.cc
blob9172500e9628dc2b27688666dc2492c600455a5d
1 // Copyright (c) 2011 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/message_loop.h"
6 #include "chrome/browser/tab_first_render_watcher.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/views/dom_view.h"
9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/views/widget/widget.h"
14 namespace {
16 views::Widget* CreateWindowForContents(views::View* contents) {
17 views::Widget::InitParams widget_params(
18 views::Widget::InitParams::TYPE_WINDOW);
20 views::Widget* widget = new views::Widget;
21 widget->Init(widget_params);
22 widget->SetContentsView(contents);
24 return widget;
27 } // namespace
29 class TabFirstRenderWatcherTest : public InProcessBrowserTest,
30 public TabFirstRenderWatcher::Delegate {
31 public:
32 TabFirstRenderWatcherTest()
33 : host_created_(false),
34 main_frame_loaded_(false),
35 main_frame_rendered_(false) {
38 // TabFirstRenderWatcher::Delegate implementation.
39 virtual void OnRenderHostCreated(RenderViewHost* host) OVERRIDE {
40 host_created_ = true;
43 virtual void OnTabMainFrameLoaded() OVERRIDE {
44 main_frame_loaded_ = true;
45 MessageLoop::current()->Quit();
48 virtual void OnTabMainFrameFirstRender() OVERRIDE {
49 main_frame_rendered_ = true;
50 MessageLoop::current()->Quit();
53 protected:
54 bool host_created_;
55 bool main_frame_loaded_;
56 bool main_frame_rendered_;
59 // Migrated from HtmlDialogBrowserTest.TestStateTransition, which times out
60 // about 5~10% of runs. See crbug.com/86059.
61 IN_PROC_BROWSER_TEST_F(TabFirstRenderWatcherTest,
62 DISABLED_TestStateTransition) {
63 DOMView* dom_view = new DOMView;
64 dom_view->Init(browser()->profile(), NULL);
65 CreateWindowForContents(dom_view);
66 dom_view->GetWidget()->Show();
68 scoped_ptr<TabFirstRenderWatcher> watcher(
69 new TabFirstRenderWatcher(dom_view->dom_contents()->web_contents(),
70 this));
72 EXPECT_FALSE(host_created_);
73 EXPECT_FALSE(main_frame_loaded_);
74 EXPECT_FALSE(main_frame_rendered_);
76 dom_view->LoadURL(GURL(chrome::kChromeUIChromeURLsURL));
77 EXPECT_TRUE(host_created_);
79 // OnTabMainFrameLoaded() will Quit().
80 MessageLoopForUI::current()->Run();
81 EXPECT_TRUE(main_frame_loaded_);
83 // OnTabMainFrameFirstRender() will Quit().
84 MessageLoopForUI::current()->Run();
85 EXPECT_TRUE(main_frame_rendered_);
87 dom_view->GetWidget()->Close();