| 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 "chrome/browser/dom_distiller/dom_distiller_service_factory.h" | 9 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" |
| 10 #include "chrome/browser/dom_distiller/tab_utils.h" | 10 #include "chrome/browser/dom_distiller/tab_utils.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" | 16 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" |
| 17 #include "components/dom_distiller/core/dom_distiller_service.h" | 17 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 18 #include "components/dom_distiller/core/task_tracker.h" | 18 #include "components/dom_distiller/core/task_tracker.h" |
| 19 #include "components/dom_distiller/core/url_constants.h" | 19 #include "components/dom_distiller/core/url_constants.h" |
| 20 #include "components/dom_distiller/core/url_utils.h" | 20 #include "components/dom_distiller/core/url_utils.h" |
| 21 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_observer.h" | 23 #include "content/public/browser/web_contents_observer.h" |
| 24 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
| 25 #include "content/public/test/test_utils.h" |
| 25 #include "net/test/embedded_test_server/embedded_test_server.h" | 26 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 28 |
| 28 namespace dom_distiller { | 29 namespace dom_distiller { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 const char* kSimpleArticlePath = "/dom_distiller/simple_article.html"; | 32 const char* kSimpleArticlePath = "/dom_distiller/simple_article.html"; |
| 32 } // namespace | 33 } // namespace |
| 33 | 34 |
| 34 class DomDistillerTabUtilsBrowserTest : public InProcessBrowserTest { | 35 class DomDistillerTabUtilsBrowserTest : public InProcessBrowserTest { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // Wait until the new WebContents has fully navigated. | 80 // Wait until the new WebContents has fully navigated. |
| 80 content::WebContents* after_web_contents = | 81 content::WebContents* after_web_contents = |
| 81 browser()->tab_strip_model()->GetActiveWebContents(); | 82 browser()->tab_strip_model()->GetActiveWebContents(); |
| 82 ASSERT_TRUE(after_web_contents != NULL); | 83 ASSERT_TRUE(after_web_contents != NULL); |
| 83 base::RunLoop new_url_loaded_runner; | 84 base::RunLoop new_url_loaded_runner; |
| 84 scoped_ptr<WebContentsMainFrameHelper> distilled_page_loaded( | 85 scoped_ptr<WebContentsMainFrameHelper> distilled_page_loaded( |
| 85 new WebContentsMainFrameHelper(after_web_contents, | 86 new WebContentsMainFrameHelper(after_web_contents, |
| 86 new_url_loaded_runner.QuitClosure())); | 87 new_url_loaded_runner.QuitClosure())); |
| 87 new_url_loaded_runner.Run(); | 88 new_url_loaded_runner.Run(); |
| 88 | 89 |
| 90 std::string page_title; |
| 91 content::ExecuteScriptAndGetValue(after_web_contents->GetMainFrame(), |
| 92 "document.title")->GetAsString(&page_title); |
| 93 |
| 89 // Verify the new URL is showing distilled content in a new WebContents. | 94 // Verify the new URL is showing distilled content in a new WebContents. |
| 90 EXPECT_NE(initial_web_contents, after_web_contents); | 95 EXPECT_NE(initial_web_contents, after_web_contents); |
| 91 EXPECT_TRUE( | 96 EXPECT_TRUE( |
| 92 after_web_contents->GetLastCommittedURL().SchemeIs(kDomDistillerScheme)); | 97 after_web_contents->GetLastCommittedURL().SchemeIs(kDomDistillerScheme)); |
| 93 EXPECT_EQ("Test Page Title", | 98 EXPECT_EQ("Test Page Title", page_title); |
| 94 base::UTF16ToUTF8(after_web_contents->GetTitle())); | |
| 95 } | 99 } |
| 96 | 100 |
| 97 IN_PROC_BROWSER_TEST_F(DomDistillerTabUtilsBrowserTest, | 101 IN_PROC_BROWSER_TEST_F(DomDistillerTabUtilsBrowserTest, |
| 98 TestDistillIntoWebContents) { | 102 TestDistillIntoWebContents) { |
| 99 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 103 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 100 | 104 |
| 101 content::WebContents* source_web_contents = | 105 content::WebContents* source_web_contents = |
| 102 browser()->tab_strip_model()->GetActiveWebContents(); | 106 browser()->tab_strip_model()->GetActiveWebContents(); |
| 103 const GURL& article_url = embedded_test_server()->GetURL(kSimpleArticlePath); | 107 const GURL& article_url = embedded_test_server()->GetURL(kSimpleArticlePath); |
| 104 | 108 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 EXPECT_EQ("Test Page Title", | 141 EXPECT_EQ("Test Page Title", |
| 138 base::UTF16ToUTF8(destination_web_contents->GetTitle())); | 142 base::UTF16ToUTF8(destination_web_contents->GetTitle())); |
| 139 | 143 |
| 140 content::WebContentsDestroyedWatcher destroyed_watcher( | 144 content::WebContentsDestroyedWatcher destroyed_watcher( |
| 141 destination_web_contents); | 145 destination_web_contents); |
| 142 browser()->tab_strip_model()->CloseWebContentsAt(1, 0); | 146 browser()->tab_strip_model()->CloseWebContentsAt(1, 0); |
| 143 destroyed_watcher.Wait(); | 147 destroyed_watcher.Wait(); |
| 144 } | 148 } |
| 145 | 149 |
| 146 } // namespace dom_distiller | 150 } // namespace dom_distiller |
| OLD | NEW |