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 "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 | 27 |
27 namespace dom_distiller { | 28 namespace dom_distiller { |
28 | 29 |
29 namespace { | 30 namespace { |
30 const char* kSimpleArticlePath = "/dom_distiller/simple_article.html"; | 31 const char* kSimpleArticlePath = "/dom_distiller/simple_article.html"; |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 class DomDistillerTabUtilsBrowserTest : public InProcessBrowserTest { | 34 class DomDistillerTabUtilsBrowserTest : public InProcessBrowserTest { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 new_url_loaded_runner.Run(); | 87 new_url_loaded_runner.Run(); |
87 | 88 |
88 // Verify the new URL is showing distilled content in a new WebContents. | 89 // Verify the new URL is showing distilled content in a new WebContents. |
89 EXPECT_NE(initial_web_contents, after_web_contents); | 90 EXPECT_NE(initial_web_contents, after_web_contents); |
90 EXPECT_TRUE( | 91 EXPECT_TRUE( |
91 after_web_contents->GetLastCommittedURL().SchemeIs(kDomDistillerScheme)); | 92 after_web_contents->GetLastCommittedURL().SchemeIs(kDomDistillerScheme)); |
92 EXPECT_EQ("Test Page Title", | 93 EXPECT_EQ("Test Page Title", |
93 base::UTF16ToUTF8(after_web_contents->GetTitle())); | 94 base::UTF16ToUTF8(after_web_contents->GetTitle())); |
94 } | 95 } |
95 | 96 |
| 97 IN_PROC_BROWSER_TEST_F(DomDistillerTabUtilsBrowserTest, |
| 98 TestDistillIntoWebContents) { |
| 99 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 100 |
| 101 content::WebContents* source_web_contents = |
| 102 browser()->tab_strip_model()->GetActiveWebContents(); |
| 103 const GURL& article_url = embedded_test_server()->GetURL(kSimpleArticlePath); |
| 104 |
| 105 // This blocks until the navigation has completely finished. |
| 106 ui_test_utils::NavigateToURL(browser(), article_url); |
| 107 |
| 108 // Create destination WebContents. |
| 109 content::WebContents::CreateParams create_params( |
| 110 source_web_contents->GetBrowserContext()); |
| 111 content::WebContents* destination_web_contents = |
| 112 content::WebContents::Create(create_params); |
| 113 DCHECK(destination_web_contents); |
| 114 |
| 115 browser()->tab_strip_model()->AppendWebContents(destination_web_contents, |
| 116 true); |
| 117 ASSERT_EQ(destination_web_contents, |
| 118 browser()->tab_strip_model()->GetWebContentsAt(1)); |
| 119 |
| 120 DistillAndView(source_web_contents, destination_web_contents); |
| 121 |
| 122 // Wait until the destination WebContents has fully navigated. |
| 123 base::RunLoop new_url_loaded_runner; |
| 124 scoped_ptr<WebContentsMainFrameHelper> distilled_page_loaded( |
| 125 new WebContentsMainFrameHelper(destination_web_contents, |
| 126 new_url_loaded_runner.QuitClosure())); |
| 127 new_url_loaded_runner.Run(); |
| 128 |
| 129 // Verify that the source WebContents is showing the original article. |
| 130 EXPECT_EQ(article_url, source_web_contents->GetLastCommittedURL()); |
| 131 EXPECT_EQ("Test Page Title", |
| 132 base::UTF16ToUTF8(source_web_contents->GetTitle())); |
| 133 |
| 134 // Verify the destination WebContents is showing distilled content. |
| 135 EXPECT_TRUE(destination_web_contents->GetLastCommittedURL().SchemeIs( |
| 136 kDomDistillerScheme)); |
| 137 EXPECT_EQ("Test Page Title", |
| 138 base::UTF16ToUTF8(destination_web_contents->GetTitle())); |
| 139 |
| 140 content::WebContentsDestroyedWatcher destroyed_watcher( |
| 141 destination_web_contents); |
| 142 browser()->tab_strip_model()->CloseWebContentsAt(1, 0); |
| 143 destroyed_watcher.Wait(); |
| 144 } |
| 145 |
96 } // namespace dom_distiller | 146 } // namespace dom_distiller |
OLD | NEW |