Home | History | Annotate | Download | only in webui
      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/ui/browser.h"
      6 #include "chrome/browser/ui/tabs/tab_strip_model.h"
      7 #include "chrome/common/url_constants.h"
      8 #include "chrome/test/base/in_process_browser_test.h"
      9 #include "chrome/test/base/ui_test_utils.h"
     10 #include "content/public/browser/navigation_details.h"
     11 #include "content/public/browser/web_contents.h"
     12 #include "content/public/test/browser_test_utils.h"
     13 
     14 using content::WebContents;
     15 
     16 namespace {
     17 
     18 const char kSharedWorkerTestPage[] =
     19     "files/workers/workers_ui_shared_worker.html";
     20 const char kSharedWorkerJs[] =
     21     "files/workers/workers_ui_shared_worker.js";
     22 
     23 class InspectUITest : public InProcessBrowserTest {
     24  public:
     25   InspectUITest() {}
     26 
     27  private:
     28   DISALLOW_COPY_AND_ASSIGN(InspectUITest);
     29 };
     30 
     31 // The test fails on Mac OS X and Windows, see crbug.com/89583
     32 // Intermittently fails on Linux.
     33 IN_PROC_BROWSER_TEST_F(InspectUITest, DISABLED_SharedWorkersList) {
     34   ASSERT_TRUE(test_server()->Start());
     35   GURL url = test_server()->GetURL(kSharedWorkerTestPage);
     36   ui_test_utils::NavigateToURL(browser(), url);
     37 
     38   ui_test_utils::NavigateToURLWithDisposition(
     39       browser(),
     40       GURL(chrome::kChromeUIInspectURL),
     41       NEW_FOREGROUND_TAB,
     42       ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
     43 
     44   WebContents* web_contents =
     45       browser()->tab_strip_model()->GetActiveWebContents();
     46   ASSERT_TRUE(web_contents != NULL);
     47 
     48   std::string result;
     49   ASSERT_TRUE(
     50       content::ExecuteScriptAndExtractString(
     51           web_contents,
     52           "window.domAutomationController.send("
     53           "    '' + document.body.textContent);",
     54           &result));
     55   ASSERT_TRUE(result.find(kSharedWorkerJs) != std::string::npos);
     56   ASSERT_TRUE(result.find(kSharedWorkerTestPage) != std::string::npos);
     57 }
     58 
     59 IN_PROC_BROWSER_TEST_F(InspectUITest, ReloadCrash) {
     60   ASSERT_TRUE(test_server()->Start());
     61   // Make sure that loading the inspect UI twice in the same tab
     62   // connects/disconnects listeners without crashing.
     63   ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIInspectURL));
     64   ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIInspectURL));
     65 }
     66 
     67 }  // namespace
     68