Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / printing / print_preview_test.cc
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 "chrome/browser/printing/print_preview_test.h"
6
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_iterator.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/test_browser_window.h"
11 #include "components/web_modal/web_contents_modal_dialog_host.h"
12 #include "content/public/browser/plugin_service.h"
13 #include "content/public/browser/web_contents.h"
14
15 using web_modal::WebContentsModalDialogHost;
16 using web_modal::ModalDialogHostObserver;
17
18 namespace {
19
20 // Use a custom test browser window to provide a parent view to the print
21 // preview dialog.
22 class PrintPreviewTestBrowserWindow
23     : public TestBrowserWindow,
24       public WebContentsModalDialogHost {
25  public:
26   PrintPreviewTestBrowserWindow() {}
27
28   // BrowserWindow overrides
29   WebContentsModalDialogHost* GetWebContentsModalDialogHost() override {
30     return this;
31   }
32
33   // WebContentsModalDialogHost overrides
34
35   // The web contents modal dialog must be parented to *something*; use the
36   // WebContents window since there is no true browser window for unit tests.
37   gfx::NativeView GetHostView() const override {
38     return FindBrowser()->tab_strip_model()->GetActiveWebContents()->
39         GetNativeView();
40   }
41
42   gfx::Point GetDialogPosition(const gfx::Size& size) override {
43     return gfx::Point();
44   }
45
46   gfx::Size GetMaximumDialogSize() override { return gfx::Size(); }
47
48   void AddObserver(ModalDialogHostObserver* observer) override {}
49   void RemoveObserver(ModalDialogHostObserver* observer) override {}
50
51  private:
52   Browser* FindBrowser() const {
53     for (chrome::BrowserIterator it; !it.done(); it.Next()) {
54       Browser* browser = *it;
55       if (browser->window() == this)
56         return browser;
57     }
58     NOTREACHED();
59     return NULL;
60   }
61
62   DISALLOW_COPY_AND_ASSIGN(PrintPreviewTestBrowserWindow);
63 };
64 }  // namespace
65
66 PrintPreviewTest::PrintPreviewTest() {}
67 PrintPreviewTest::~PrintPreviewTest() {}
68
69 void PrintPreviewTest::SetUp() {
70   BrowserWithTestWindowTest::SetUp();
71
72   // The PluginService will be destroyed at the end of the test (due to the
73   // ShadowingAtExitManager in our base class).
74   content::PluginService::GetInstance()->Init();
75   content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting();
76 }
77
78 BrowserWindow* PrintPreviewTest::CreateBrowserWindow() {
79   return new PrintPreviewTestBrowserWindow;
80 }