| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/favicon/content/content_favicon_driver.h" | 5 #include "components/favicon/content/content_favicon_driver.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/scoped_observer.h" | 10 #include "base/scoped_observer.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.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/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "components/favicon/core/favicon_driver_observer.h" | 20 #include "components/favicon/core/favicon_driver_observer.h" |
| 21 #include "components/favicon/core/favicon_handler.h" | 21 #include "components/favicon/core/favicon_handler.h" |
| 22 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
| 25 #include "content/public/browser/resource_dispatcher_host.h" | 25 #include "content/public/browser/resource_dispatcher_host.h" |
| 26 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 26 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 27 #include "net/base/load_flags.h" | 27 #include "net/base/load_flags.h" |
| 28 #include "net/test/spawned_test_server/spawned_test_server.h" | 28 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 29 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
| 30 #include "url/url_constants.h" | 30 #include "url/url_constants.h" |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Tracks whether the URL passed to the constructor is requested and whether | 34 // Tracks whether the URL passed to the constructor is requested and whether |
| 35 // the request bypasses the cache. | 35 // the request bypasses the cache. |
| 36 class TestResourceDispatcherHostDelegate | 36 class TestResourceDispatcherHostDelegate |
| 37 : public content::ResourceDispatcherHostDelegate { | 37 : public content::ResourceDispatcherHostDelegate { |
| 38 public: | 38 public: |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 | 197 |
| 198 private: | 198 private: |
| 199 DISALLOW_COPY_AND_ASSIGN(ContentFaviconDriverTest); | 199 DISALLOW_COPY_AND_ASSIGN(ContentFaviconDriverTest); |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 // Test that when a user reloads a page ignoring the cache that the favicon is | 202 // Test that when a user reloads a page ignoring the cache that the favicon is |
| 203 // is redownloaded and (not returned from either the favicon cache or the HTTP | 203 // is redownloaded and (not returned from either the favicon cache or the HTTP |
| 204 // cache). | 204 // cache). |
| 205 IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, ReloadIgnoringCache) { | 205 IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, ReloadIgnoringCache) { |
| 206 ASSERT_TRUE(test_server()->Start()); | 206 ASSERT_TRUE(embedded_test_server()->Start()); |
| 207 GURL url = test_server()->GetURL("files/favicon/page_with_favicon.html"); | 207 GURL url = embedded_test_server()->GetURL("/favicon/page_with_favicon.html"); |
| 208 GURL icon_url = test_server()->GetURL("files/favicon/icon.png"); | 208 GURL icon_url = embedded_test_server()->GetURL("/favicon/icon.png"); |
| 209 | 209 |
| 210 scoped_ptr<TestResourceDispatcherHostDelegate> delegate( | 210 scoped_ptr<TestResourceDispatcherHostDelegate> delegate( |
| 211 new TestResourceDispatcherHostDelegate(icon_url)); | 211 new TestResourceDispatcherHostDelegate(icon_url)); |
| 212 content::ResourceDispatcherHost::Get()->SetDelegate(delegate.get()); | 212 content::ResourceDispatcherHost::Get()->SetDelegate(delegate.get()); |
| 213 | 213 |
| 214 // Initial visit in order to populate the cache. | 214 // Initial visit in order to populate the cache. |
| 215 { | 215 { |
| 216 PendingTaskWaiter waiter(web_contents(), this); | 216 PendingTaskWaiter waiter(web_contents(), this); |
| 217 ui_test_utils::NavigateToURLWithDisposition( | 217 ui_test_utils::NavigateToURLWithDisposition( |
| 218 browser(), url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | 218 browser(), url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 237 | 237 |
| 238 // A reload ignoring the cache should refetch the favicon from the website. | 238 // A reload ignoring the cache should refetch the favicon from the website. |
| 239 { | 239 { |
| 240 PendingTaskWaiter waiter(web_contents(), this); | 240 PendingTaskWaiter waiter(web_contents(), this); |
| 241 chrome::ExecuteCommand(browser(), IDC_RELOAD_IGNORING_CACHE); | 241 chrome::ExecuteCommand(browser(), IDC_RELOAD_IGNORING_CACHE); |
| 242 waiter.Wait(); | 242 waiter.Wait(); |
| 243 } | 243 } |
| 244 ASSERT_TRUE(delegate->was_requested()); | 244 ASSERT_TRUE(delegate->was_requested()); |
| 245 EXPECT_TRUE(delegate->bypassed_cache()); | 245 EXPECT_TRUE(delegate->bypassed_cache()); |
| 246 } | 246 } |
| OLD | NEW |