| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "base/command_line.h" | |
| 6 #include "base/path_service.h" | |
| 7 #include "base/stringprintf.h" | |
| 8 #include "base/values.h" | |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/webui/web_ui_browsertest.h" | |
| 11 #include "chrome/common/chrome_paths.h" | |
| 12 #include "chrome/common/chrome_switches.h" | |
| 13 #include "chrome/test/test_tab_strip_model_observer.h" | |
| 14 #include "chrome/test/ui_test_utils.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // TODO(scr) migrate this to ui_test_utils? | |
| 21 // Cause Print on the currently selected tab of |browser|, blocking until the | |
| 22 // Print Preview tab shows up. | |
| 23 void PrintAndWaitForPrintPreviewTab( | |
| 24 Browser* browser, | |
| 25 TestTabStripModelObserver::LoadStartObserver* load_start_observer) { | |
| 26 TestTabStripModelObserver tabstrip_observer(browser->tabstrip_model(), | |
| 27 load_start_observer); | |
| 28 TabContents* initiator_tab_contents = browser->GetSelectedTabContents(); | |
| 29 browser->Print(); | |
| 30 tabstrip_observer.WaitForObservation(); | |
| 31 EXPECT_NE(initiator_tab_contents, browser->GetSelectedTabContents()); | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 // crbug.com/88104 - v8_shell#host doesn't build when host=="arm". | |
| 37 #if !defined(ARCH_CPU_ARM_FAMILY) | |
| 38 | |
| 39 class PrintPreviewWebUITest | |
| 40 : public WebUIBrowserTest, | |
| 41 public TestTabStripModelObserver::LoadStartObserver { | |
| 42 protected: | |
| 43 // WebUIBrowserTest: | |
| 44 virtual void SetUpOnMainThread() OVERRIDE { | |
| 45 WebUIBrowserTest::SetUpOnMainThread(); | |
| 46 if (!HasPDFLib()) | |
| 47 skipTest(base::StringPrintf("%s:%d: No PDF Lib.", __FILE__, __LINE__)); | |
| 48 | |
| 49 AddLibrary(FilePath(FILE_PATH_LITERAL("print_preview.js"))); | |
| 50 GURL print_preview_test_url = WebUITestDataPathToURL( | |
| 51 FILE_PATH_LITERAL("print_preview_hello_world_test.html")); | |
| 52 ui_test_utils::NavigateToURL(browser(), print_preview_test_url); | |
| 53 PrintAndWaitForPrintPreviewTab(browser(), this); | |
| 54 } | |
| 55 | |
| 56 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 57 WebUIBrowserTest::SetUpCommandLine(command_line); | |
| 58 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS) || defined(OS_MACOSX) | |
| 59 // Don't enable the flag for chrome builds, which should be on by default. | |
| 60 command_line->AppendSwitch(switches::kEnablePrintPreview); | |
| 61 #else | |
| 62 ASSERT_TRUE(switches::IsPrintPreviewEnabled()); | |
| 63 #endif | |
| 64 } | |
| 65 | |
| 66 // TestTabStripModelObserver::LoadStartObserver: | |
| 67 virtual void OnLoadStart() OVERRIDE { | |
| 68 PreLoadJavascriptLibraries(true); | |
| 69 } | |
| 70 | |
| 71 bool HasPDFLib() const { | |
| 72 FilePath pdf; | |
| 73 return PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) && | |
| 74 file_util::PathExists(pdf); | |
| 75 } | |
| 76 }; | |
| 77 | |
| 78 #include "js2webui/chrome/test/data/webui/print_preview-inl.h" | |
| 79 | |
| 80 #endif // !defined(ARCH_CPU_ARM_FAMILY) | |
| OLD | NEW |