| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "base/timer/timer.h" | 7 #include "base/timer/timer.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 14 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/host_desktop.h" | 18 #include "chrome/browser/ui/host_desktop.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "components/bookmarks/browser/bookmark_model.h" | 22 #include "components/bookmarks/browser/bookmark_model.h" |
| 23 #include "components/bookmarks/browser/bookmark_utils.h" | 23 #include "components/bookmarks/browser/bookmark_utils.h" |
| 24 #include "components/bookmarks/test/bookmark_test_helpers.h" | 24 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 25 #include "content/public/browser/interstitial_page.h" | 25 #include "content/public/browser/interstitial_page.h" |
| 26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 29 | 30 |
| 30 using bookmarks::BookmarkModel; | 31 using bookmarks::BookmarkModel; |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 const char kPersistBookmarkURL[] = "http://www.cnn.com/"; | 34 const char kPersistBookmarkURL[] = "http://www.cnn.com/"; |
| 34 const char kPersistBookmarkTitle[] = "CNN"; | 35 const char kPersistBookmarkTitle[] = "CNN"; |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 37 class TestBookmarkTabHelperDelegate : public BookmarkTabHelperDelegate { | 38 class TestBookmarkTabHelperDelegate : public BookmarkTabHelperDelegate { |
| 38 public: | 39 public: |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 #if defined(OS_LINUX) | 164 #if defined(OS_LINUX) |
| 164 #define MAYBE_HideStarOnNonbookmarkedInterstitial \ | 165 #define MAYBE_HideStarOnNonbookmarkedInterstitial \ |
| 165 DISABLED_HideStarOnNonbookmarkedInterstitial | 166 DISABLED_HideStarOnNonbookmarkedInterstitial |
| 166 #else | 167 #else |
| 167 #define MAYBE_HideStarOnNonbookmarkedInterstitial \ | 168 #define MAYBE_HideStarOnNonbookmarkedInterstitial \ |
| 168 HideStarOnNonbookmarkedInterstitial | 169 HideStarOnNonbookmarkedInterstitial |
| 169 #endif | 170 #endif |
| 170 IN_PROC_BROWSER_TEST_F(BookmarkBrowsertest, | 171 IN_PROC_BROWSER_TEST_F(BookmarkBrowsertest, |
| 171 MAYBE_HideStarOnNonbookmarkedInterstitial) { | 172 MAYBE_HideStarOnNonbookmarkedInterstitial) { |
| 172 // Start an HTTPS server with a certificate error. | 173 // Start an HTTPS server with a certificate error. |
| 173 net::SpawnedTestServer::SSLOptions https_options; | 174 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 174 https_options.server_certificate = | 175 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 175 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 176 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 176 net::SpawnedTestServer https_server( | |
| 177 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
| 178 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 179 ASSERT_TRUE(https_server.Start()); | 177 ASSERT_TRUE(https_server.Start()); |
| 178 ASSERT_TRUE(embedded_test_server()->Start()); |
| 180 | 179 |
| 181 BookmarkModel* bookmark_model = WaitForBookmarkModel(browser()->profile()); | 180 BookmarkModel* bookmark_model = WaitForBookmarkModel(browser()->profile()); |
| 182 GURL bookmark_url = test_server()->GetURL("http://example.test"); | 181 GURL bookmark_url = embedded_test_server()->GetURL("example.test", "/"); |
| 183 bookmarks::AddIfNotBookmarked(bookmark_model, | 182 bookmarks::AddIfNotBookmarked(bookmark_model, |
| 184 bookmark_url, | 183 bookmark_url, |
| 185 base::ASCIIToUTF16("Bookmark")); | 184 base::ASCIIToUTF16("Bookmark")); |
| 186 | 185 |
| 187 TestBookmarkTabHelperDelegate bookmark_delegate; | 186 TestBookmarkTabHelperDelegate bookmark_delegate; |
| 188 content::WebContents* web_contents = | 187 content::WebContents* web_contents = |
| 189 browser()->tab_strip_model()->GetActiveWebContents(); | 188 browser()->tab_strip_model()->GetActiveWebContents(); |
| 190 BookmarkTabHelper* tab_helper = | 189 BookmarkTabHelper* tab_helper = |
| 191 BookmarkTabHelper::FromWebContents(web_contents); | 190 BookmarkTabHelper::FromWebContents(web_contents); |
| 192 tab_helper->set_delegate(&bookmark_delegate); | 191 tab_helper->set_delegate(&bookmark_delegate); |
| 193 | 192 |
| 194 // Go to a bookmarked url. Bookmark star should show. | 193 // Go to a bookmarked url. Bookmark star should show. |
| 195 ui_test_utils::NavigateToURL(browser(), bookmark_url); | 194 ui_test_utils::NavigateToURL(browser(), bookmark_url); |
| 196 EXPECT_FALSE(web_contents->ShowingInterstitialPage()); | 195 EXPECT_FALSE(web_contents->ShowingInterstitialPage()); |
| 197 EXPECT_TRUE(bookmark_delegate.is_starred()); | 196 EXPECT_TRUE(bookmark_delegate.is_starred()); |
| 198 | 197 |
| 199 // Now go to a non-bookmarked url which triggers an SSL warning. Bookmark | 198 // Now go to a non-bookmarked url which triggers an SSL warning. Bookmark |
| 200 // star should disappear. | 199 // star should disappear. |
| 201 GURL error_url = https_server.GetURL("."); | 200 GURL error_url = https_server.GetURL("/"); |
| 202 ui_test_utils::NavigateToURL(browser(), error_url); | 201 ui_test_utils::NavigateToURL(browser(), error_url); |
| 203 web_contents = browser()->tab_strip_model()->GetActiveWebContents(); | 202 web_contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 204 content::WaitForInterstitialAttach(web_contents); | 203 content::WaitForInterstitialAttach(web_contents); |
| 205 EXPECT_TRUE(web_contents->ShowingInterstitialPage()); | 204 EXPECT_TRUE(web_contents->ShowingInterstitialPage()); |
| 206 EXPECT_FALSE(bookmark_delegate.is_starred()); | 205 EXPECT_FALSE(bookmark_delegate.is_starred()); |
| 207 | 206 |
| 208 // The delegate is required to outlive the tab helper. | 207 // The delegate is required to outlive the tab helper. |
| 209 tab_helper->set_delegate(nullptr); | 208 tab_helper->set_delegate(nullptr); |
| 210 } | 209 } |
| OLD | NEW |