| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" | 10 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "content/public/browser/web_contents_observer.h" | 25 #include "content/public/browser/web_contents_observer.h" |
| 26 #include "content/public/common/isolated_world_ids.h" | 26 #include "content/public/common/isolated_world_ids.h" |
| 27 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
| 28 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
| 29 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 31 |
| 32 namespace dom_distiller { | 32 namespace dom_distiller { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 |
| 35 const char* kSimpleArticlePath = "/dom_distiller/simple_article.html"; | 36 const char* kSimpleArticlePath = "/dom_distiller/simple_article.html"; |
| 37 |
| 38 static bool hit_javascript_error = false; |
| 39 |
| 40 bool JavascriptErrorDetectingLogHandler(int severity, |
| 41 const char* file, |
| 42 int line, |
| 43 size_t message_start, |
| 44 const std::string& str) { |
| 45 if (file == NULL || std::string("CONSOLE") != file) |
| 46 return false; |
| 47 |
| 48 // Catch CSP violation as well. |
| 49 bool contains_error = str.find(" violates ") != std::string::npos; |
| 50 if (severity == logging::LOG_ERROR || |
| 51 (severity == logging::LOG_INFO && contains_error)) { |
| 52 hit_javascript_error = true; |
| 53 } |
| 54 |
| 55 return false; |
| 56 } |
| 57 |
| 36 } // namespace | 58 } // namespace |
| 37 | 59 |
| 38 class DomDistillerTabUtilsBrowserTest : public InProcessBrowserTest { | 60 class DomDistillerTabUtilsBrowserTest : public InProcessBrowserTest { |
| 39 public: | 61 public: |
| 62 DomDistillerTabUtilsBrowserTest() { |
| 63 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler); |
| 64 hit_javascript_error = false; |
| 65 } |
| 66 |
| 67 ~DomDistillerTabUtilsBrowserTest() override { |
| 68 logging::SetLogMessageHandler(nullptr); |
| 69 } |
| 70 |
| 40 void SetUpOnMainThread() override { | 71 void SetUpOnMainThread() override { |
| 41 if (!DistillerJavaScriptWorldIdIsSet()) { | 72 if (!DistillerJavaScriptWorldIdIsSet()) { |
| 42 SetDistillerJavaScriptWorldId(content::ISOLATED_WORLD_ID_CONTENT_END); | 73 SetDistillerJavaScriptWorldId(content::ISOLATED_WORLD_ID_CONTENT_END); |
| 43 } | 74 } |
| 44 InProcessBrowserTest::SetUpOnMainThread(); | 75 InProcessBrowserTest::SetUpOnMainThread(); |
| 45 } | 76 } |
| 46 | 77 |
| 47 void SetUpCommandLine(base::CommandLine* command_line) override { | 78 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 48 command_line->AppendSwitch(switches::kEnableDomDistiller); | 79 command_line->AppendSwitch(switches::kEnableDomDistiller); |
| 49 } | 80 } |
| 81 |
| 82 void TearDown() override { |
| 83 EXPECT_FALSE(hit_javascript_error); |
| 84 } |
| 50 }; | 85 }; |
| 51 | 86 |
| 52 // WebContentsMainFrameHelper is used to detect if a distilled page has | 87 // WebContentsMainFrameHelper is used to detect if a distilled page has |
| 53 // finished loading. This is done by checking how many times the title has | 88 // finished loading. This is done by checking how many times the title has |
| 54 // been set rather than using "DidFinishLoad" directly due to the content | 89 // been set rather than using "DidFinishLoad" directly due to the content |
| 55 // being set by JavaScript. | 90 // being set by JavaScript. |
| 56 class WebContentsMainFrameHelper : public content::WebContentsObserver { | 91 class WebContentsMainFrameHelper : public content::WebContentsObserver { |
| 57 public: | 92 public: |
| 58 WebContentsMainFrameHelper(content::WebContents* web_contents, | 93 WebContentsMainFrameHelper(content::WebContents* web_contents, |
| 59 const base::Closure& callback) | 94 const base::Closure& callback) |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 "document.title")->GetAsString(&page_title); | 208 "document.title")->GetAsString(&page_title); |
| 174 EXPECT_EQ("Test Page Title", page_title); | 209 EXPECT_EQ("Test Page Title", page_title); |
| 175 | 210 |
| 176 content::WebContentsDestroyedWatcher destroyed_watcher( | 211 content::WebContentsDestroyedWatcher destroyed_watcher( |
| 177 destination_web_contents); | 212 destination_web_contents); |
| 178 browser()->tab_strip_model()->CloseWebContentsAt(1, 0); | 213 browser()->tab_strip_model()->CloseWebContentsAt(1, 0); |
| 179 destroyed_watcher.Wait(); | 214 destroyed_watcher.Wait(); |
| 180 } | 215 } |
| 181 | 216 |
| 182 } // namespace dom_distiller | 217 } // namespace dom_distiller |
| OLD | NEW |