Chromium Code Reviews| 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 <deque> | 5 #include <deque> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 #include "chrome/browser/prerender/prerender_manager.h" | 41 #include "chrome/browser/prerender/prerender_manager.h" |
| 42 #include "chrome/browser/prerender/prerender_manager_factory.h" | 42 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 43 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
| 44 #include "chrome/browser/profiles/profile_io_data.h" | 44 #include "chrome/browser/profiles/profile_io_data.h" |
| 45 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h" | 45 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h" |
| 46 #include "chrome/browser/safe_browsing/database_manager.h" | 46 #include "chrome/browser/safe_browsing/database_manager.h" |
| 47 #include "chrome/browser/safe_browsing/local_database_manager.h" | 47 #include "chrome/browser/safe_browsing/local_database_manager.h" |
| 48 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 48 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 49 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 49 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 50 #include "chrome/browser/safe_browsing/test_database_manager.h" | 50 #include "chrome/browser/safe_browsing/test_database_manager.h" |
| 51 #include "chrome/browser/task_management/providers/task_provider_observer.h" | |
| 52 #include "chrome/browser/task_management/providers/web_contents/web_contents_tag s_manager.h" | |
| 53 #include "chrome/browser/task_management/providers/web_contents/web_contents_tas k_provider.h" | |
| 51 #include "chrome/browser/task_manager/task_manager.h" | 54 #include "chrome/browser/task_manager/task_manager.h" |
| 52 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 55 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
| 53 #include "chrome/browser/ui/browser.h" | 56 #include "chrome/browser/ui/browser.h" |
| 54 #include "chrome/browser/ui/browser_commands.h" | 57 #include "chrome/browser/ui/browser_commands.h" |
| 55 #include "chrome/browser/ui/browser_finder.h" | 58 #include "chrome/browser/ui/browser_finder.h" |
| 56 #include "chrome/browser/ui/browser_navigator.h" | 59 #include "chrome/browser/ui/browser_navigator.h" |
| 57 #include "chrome/browser/ui/browser_window.h" | 60 #include "chrome/browser/ui/browser_window.h" |
| 58 #include "chrome/browser/ui/location_bar/location_bar.h" | 61 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 59 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 62 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 60 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 63 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| (...skipping 4012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4073 WebContents* web_contents = | 4076 WebContents* web_contents = |
| 4074 browser()->tab_strip_model()->GetActiveWebContents(); | 4077 browser()->tab_strip_model()->GetActiveWebContents(); |
| 4075 bool display_test_result = false; | 4078 bool display_test_result = false; |
| 4076 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents, | 4079 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents, |
| 4077 "DidDisplayReallyPass()", | 4080 "DidDisplayReallyPass()", |
| 4078 &display_test_result)); | 4081 &display_test_result)); |
| 4079 ASSERT_TRUE(display_test_result); | 4082 ASSERT_TRUE(display_test_result); |
| 4080 } | 4083 } |
| 4081 #endif // !defined(DISABLE_NACL) | 4084 #endif // !defined(DISABLE_NACL) |
| 4082 | 4085 |
| 4086 #if defined(ENABLE_TASK_MANAGER) | |
| 4087 | |
| 4088 namespace { | |
| 4089 | |
| 4090 const char kPrerenderPage[] = "files/prerender/prerender_page.html"; | |
|
gavinp
2015/06/23 17:09:16
Every other test just repeats this string. I don't
afakhry
2015/06/23 19:02:47
Done! Used the literal as the other tests.
| |
| 4091 | |
| 4092 // Defines a test class for testing that will act as a mock task manager. | |
| 4093 class MockTaskManager : public task_management::TaskProviderObserver { | |
| 4094 public: | |
| 4095 MockTaskManager() {} | |
| 4096 ~MockTaskManager() override {} | |
| 4097 | |
| 4098 // task_management::Task_providerObserver: | |
| 4099 void TaskAdded(task_management::Task* task) override { | |
| 4100 EXPECT_FALSE(provided_tasks_.count(task)); | |
|
Lei Zhang
2015/06/23 18:34:33
ContainsKey(provided_tasks_, task) might be slight
afakhry
2015/06/23 19:02:47
Done.
| |
| 4101 provided_tasks_.insert(task); | |
| 4102 } | |
| 4103 | |
| 4104 void TaskRemoved(task_management::Task* task) override { | |
| 4105 EXPECT_TRUE(provided_tasks_.count(task)); | |
| 4106 provided_tasks_.erase(task); | |
| 4107 } | |
| 4108 | |
| 4109 base::string16 GetPrerenderTitlePrefix() const { | |
| 4110 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, | |
| 4111 base::string16()); | |
| 4112 } | |
| 4113 | |
| 4114 const std::set<task_management::WebContentsTag*>& tracked_tags() const { | |
| 4115 return task_management::WebContentsTagsManager::GetInstance()-> | |
| 4116 tracked_tags(); | |
| 4117 } | |
| 4118 | |
| 4119 const std::set<task_management::Task*>& provided_tasks() const { | |
| 4120 return provided_tasks_; | |
| 4121 } | |
| 4122 | |
| 4123 private: | |
| 4124 std::set<task_management::Task*> provided_tasks_; | |
| 4125 | |
| 4126 DISALLOW_COPY_AND_ASSIGN(MockTaskManager); | |
| 4127 }; | |
| 4128 | |
| 4129 } // namespace | |
|
gavinp
2015/06/23 17:09:16
Why not put the tests in the unnamed namespace too
afakhry
2015/06/23 19:02:47
Done.
| |
| 4130 | |
| 4131 // Tests the correct recording of tags for the prerender WebContents. | |
| 4132 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, TaskManagementTagsBasic) { | |
| 4133 MockTaskManager task_manager; | |
| 4134 EXPECT_TRUE(task_manager.tracked_tags().empty()); | |
| 4135 | |
| 4136 // Start prerendering a page and make sure it's correctly tagged. | |
| 4137 PrerenderTestURL(kPrerenderPage, FINAL_STATUS_USED, 1); | |
| 4138 EXPECT_FALSE(task_manager.tracked_tags().empty()); | |
| 4139 | |
| 4140 // TODO(afakhry): Once we start tagging the tab contents the below tests | |
| 4141 // must be changed. | |
| 4142 EXPECT_EQ(1U, task_manager.tracked_tags().size()); | |
| 4143 | |
| 4144 // Swap in the prerendered content and make sure its tag is removed. | |
| 4145 NavigateToDestURL(); | |
| 4146 EXPECT_TRUE(task_manager.tracked_tags().empty()); | |
| 4147 } | |
| 4148 | |
| 4149 // Tests that the task manager will be provided by tasks that correspond to | |
| 4150 // prerendered WebContents. | |
| 4151 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, TaskManagementTasksProvided) { | |
| 4152 MockTaskManager task_manager; | |
| 4153 EXPECT_TRUE(task_manager.tracked_tags().empty()); | |
| 4154 | |
| 4155 task_management::WebContentsTaskProvider provider; | |
| 4156 provider.SetObserver(&task_manager); | |
| 4157 | |
| 4158 // Still empty, no pre-existing tasks. | |
| 4159 EXPECT_TRUE(task_manager.provided_tasks().empty()); | |
| 4160 | |
| 4161 // Start prerendering a page. | |
| 4162 PrerenderTestURL(kPrerenderPage, FINAL_STATUS_USED, 1); | |
| 4163 EXPECT_FALSE(task_manager.tracked_tags().empty()); | |
| 4164 | |
| 4165 // TODO(afakhry): The below may not be true after we support more tags. | |
| 4166 EXPECT_EQ(1U, task_manager.tracked_tags().size()); | |
| 4167 ASSERT_FALSE(task_manager.provided_tasks().empty()); | |
|
Lei Zhang
2015/06/23 18:34:34
I don't think you need this since you have a bette
afakhry
2015/06/23 19:02:47
Done.
| |
| 4168 ASSERT_EQ(1U, task_manager.provided_tasks().size()); | |
| 4169 | |
| 4170 const task_management::Task* task = *task_manager.provided_tasks().begin(); | |
| 4171 EXPECT_EQ(task_management::Task::RENDERER, task->GetType()); | |
| 4172 const base::string16 title = task->title(); | |
| 4173 const base::string16 expected_prefix = task_manager.GetPrerenderTitlePrefix(); | |
| 4174 EXPECT_TRUE(base::StartsWith(title, | |
| 4175 expected_prefix, | |
| 4176 base::CompareCase::INSENSITIVE_ASCII)); | |
| 4177 | |
| 4178 NavigateToDestURL(); | |
| 4179 // TODO(afakhry): The below may not be true after we support more tags. | |
| 4180 EXPECT_TRUE(task_manager.provided_tasks().empty()); | |
| 4181 } | |
| 4182 | |
| 4183 #endif // defined(ENABLE_TASK_MANAGER) | |
| 4184 | |
| 4083 } // namespace prerender | 4185 } // namespace prerender |
| OLD | NEW |