| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 // Callback for when SearchProviderInstallData is ready to have | 58 // Callback for when SearchProviderInstallData is ready to have |
| 59 // GetInstallState called. Runs all of the test cases. | 59 // GetInstallState called. Runs all of the test cases. |
| 60 void DoInstallStateTests(); | 60 void DoInstallStateTests(); |
| 61 | 61 |
| 62 // Does a verification for one url and its expected state. | 62 // Does a verification for one url and its expected state. |
| 63 void VerifyInstallState(SearchProviderInstallData::State expected_state, | 63 void VerifyInstallState(SearchProviderInstallData::State expected_state, |
| 64 const std::string& url); | 64 const std::string& url); |
| 65 | 65 |
| 66 SearchProviderInstallData* install_data_; | 66 SearchProviderInstallData* install_data_; |
| 67 MessageLoop* main_loop_; | 67 base::MessageLoop* main_loop_; |
| 68 | 68 |
| 69 // A host which should be a search provider but not the default. | 69 // A host which should be a search provider but not the default. |
| 70 std::string search_provider_host_; | 70 std::string search_provider_host_; |
| 71 | 71 |
| 72 // A host which should be a search provider but not the default. | 72 // A host which should be a search provider but not the default. |
| 73 std::string default_search_provider_host_; | 73 std::string default_search_provider_host_; |
| 74 | 74 |
| 75 // Used to indicate if DoInstallStateTests passed all test. | 75 // Used to indicate if DoInstallStateTests passed all test. |
| 76 bool passed_; | 76 bool passed_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(TestGetInstallState); | 78 DISALLOW_COPY_AND_ASSIGN(TestGetInstallState); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 TestGetInstallState::TestGetInstallState( | 81 TestGetInstallState::TestGetInstallState( |
| 82 SearchProviderInstallData* install_data) | 82 SearchProviderInstallData* install_data) |
| 83 : install_data_(install_data), | 83 : install_data_(install_data), |
| 84 main_loop_(NULL), | 84 main_loop_(NULL), |
| 85 passed_(false) { | 85 passed_(false) { |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool TestGetInstallState::RunTests() { | 88 bool TestGetInstallState::RunTests() { |
| 89 passed_ = true; | 89 passed_ = true; |
| 90 | 90 |
| 91 main_loop_ = MessageLoop::current(); | 91 main_loop_ = base::MessageLoop::current(); |
| 92 | 92 |
| 93 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask( | 93 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)->PostTask( |
| 94 FROM_HERE, | 94 FROM_HERE, |
| 95 base::Bind(&TestGetInstallState::StartTestOnIOThread, this)); | 95 base::Bind(&TestGetInstallState::StartTestOnIOThread, this)); |
| 96 // Run the current message loop. When the test is finished on the I/O thread, | 96 // Run the current message loop. When the test is finished on the I/O thread, |
| 97 // it invokes Quit, which unblocks this. | 97 // it invokes Quit, which unblocks this. |
| 98 MessageLoop::current()->Run(); | 98 base::MessageLoop::current()->Run(); |
| 99 main_loop_ = NULL; | 99 main_loop_ = NULL; |
| 100 | 100 |
| 101 // Let the testing code know what the result is. | 101 // Let the testing code know what the result is. |
| 102 return passed_; | 102 return passed_; |
| 103 } | 103 } |
| 104 | 104 |
| 105 TestGetInstallState::~TestGetInstallState() { | 105 TestGetInstallState::~TestGetInstallState() { |
| 106 } | 106 } |
| 107 | 107 |
| 108 void TestGetInstallState::StartTestOnIOThread() { | 108 void TestGetInstallState::StartTestOnIOThread() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 129 VerifyInstallState(SearchProviderInstallData::NOT_INSTALLED, | 129 VerifyInstallState(SearchProviderInstallData::NOT_INSTALLED, |
| 130 "http://a" + search_provider_host_ + "/"); | 130 "http://a" + search_provider_host_ + "/"); |
| 131 | 131 |
| 132 // Installed as default. | 132 // Installed as default. |
| 133 if (!default_search_provider_host_.empty()) { | 133 if (!default_search_provider_host_.empty()) { |
| 134 VerifyInstallState(SearchProviderInstallData::INSTALLED_AS_DEFAULT, | 134 VerifyInstallState(SearchProviderInstallData::INSTALLED_AS_DEFAULT, |
| 135 "http://" + default_search_provider_host_ + "/"); | 135 "http://" + default_search_provider_host_ + "/"); |
| 136 } | 136 } |
| 137 | 137 |
| 138 // All done. | 138 // All done. |
| 139 main_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 139 main_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void TestGetInstallState::VerifyInstallState( | 142 void TestGetInstallState::VerifyInstallState( |
| 143 SearchProviderInstallData::State expected_state, | 143 SearchProviderInstallData::State expected_state, |
| 144 const std::string& url) { | 144 const std::string& url) { |
| 145 | 145 |
| 146 SearchProviderInstallData::State actual_state = | 146 SearchProviderInstallData::State actual_state = |
| 147 install_data_->GetInstallState(GURL(url)); | 147 install_data_->GetInstallState(GURL(url)); |
| 148 if (expected_state == actual_state) | 148 if (expected_state == actual_state) |
| 149 return; | 149 return; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 // Change the Google base url. | 326 // Change the Google base url. |
| 327 google_host = "foo.com"; | 327 google_host = "foo.com"; |
| 328 util_.SetGoogleBaseURL(GURL("http://" + google_host + "/")); | 328 util_.SetGoogleBaseURL(GURL("http://" + google_host + "/")); |
| 329 // Wait for the I/O thread to process the update notification. | 329 // Wait for the I/O thread to process the update notification. |
| 330 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); | 330 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); |
| 331 | 331 |
| 332 // Verify that the change got picked up. | 332 // Verify that the change got picked up. |
| 333 test_get_install_state->set_search_provider_host(google_host); | 333 test_get_install_state->set_search_provider_host(google_host); |
| 334 EXPECT_TRUE(test_get_install_state->RunTests()); | 334 EXPECT_TRUE(test_get_install_state->RunTests()); |
| 335 } | 335 } |
| OLD | NEW |