| 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 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ |
| 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ | 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | |
| 15 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 16 #include "components/search_engines/template_url_service_observer.h" | 14 #include "components/search_engines/template_url_service_observer.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 | 16 |
| 19 class GURL; | 17 class GURL; |
| 20 class TemplateURLService; | 18 class TemplateURLService; |
| 21 class TestingProfile; | 19 class TestingProfile; |
| 22 class TestingTemplateURLService; | 20 class TestingTemplateURLService; |
| 23 class TestingProfile; | |
| 24 | 21 |
| 25 // TemplateURLServiceTestUtilBase contains basic API to ease testing of | 22 class TemplateURLServiceTestUtil : public TemplateURLServiceObserver { |
| 26 // TemplateURLService. User should take care of the infrastructure separately. | |
| 27 class TemplateURLServiceTestUtilBase : public TemplateURLServiceObserver { | |
| 28 public: | 23 public: |
| 29 TemplateURLServiceTestUtilBase(); | 24 TemplateURLServiceTestUtil(); |
| 30 virtual ~TemplateURLServiceTestUtilBase(); | 25 virtual ~TemplateURLServiceTestUtil(); |
| 31 | |
| 32 void CreateTemplateUrlService(); | |
| 33 | 26 |
| 34 // TemplateURLServiceObserver implemementation. | 27 // TemplateURLServiceObserver implemementation. |
| 35 virtual void OnTemplateURLServiceChanged() OVERRIDE; | 28 virtual void OnTemplateURLServiceChanged() OVERRIDE; |
| 36 | 29 |
| 37 // Gets the observer count. | 30 // Gets the observer count. |
| 38 int GetObserverCount(); | 31 int GetObserverCount(); |
| 39 | 32 |
| 40 // Sets the observer count to 0. | 33 // Sets the observer count to 0. |
| 41 void ResetObserverCount(); | 34 void ResetObserverCount(); |
| 42 | 35 |
| 43 // Makes sure the load was successful and sent the correct notification. | 36 // Makes sure the load was successful and sent the correct notification. |
| 44 void VerifyLoad(); | 37 void VerifyLoad(); |
| 45 | 38 |
| 46 // Makes the model believe it has been loaded (without actually doing the | 39 // Makes the model believe it has been loaded (without actually doing the |
| 47 // load). Since this avoids setting the built-in keyword version, the next | 40 // load). Since this avoids setting the built-in keyword version, the next |
| 48 // load will do a merge from prepopulated data. | 41 // load will do a merge from prepopulated data. |
| 49 void ChangeModelToLoadState(); | 42 void ChangeModelToLoadState(); |
| 50 | 43 |
| 51 // Deletes the current model (and doesn't create a new one). | 44 // Deletes the current model (and doesn't create a new one). |
| 52 void ClearModel(); | 45 void ClearModel(); |
| 53 | 46 |
| 54 // Creates a new TemplateURLService. | 47 // Creates a new TemplateURLService. |
| 55 void ResetModel(bool verify_load); | 48 void ResetModel(bool verify_load); |
| 56 | 49 |
| 57 // Returns the search term from the last invocation of | 50 // Returns the search term from the last invocation of |
| 58 // TemplateURLService::SetKeywordSearchTermsForURL and clears the search term. | 51 // TemplateURLService::SetKeywordSearchTermsForURL and clears the search term. |
| 59 base::string16 GetAndClearSearchTerm(); | 52 base::string16 GetAndClearSearchTerm(); |
| 60 | 53 |
| 61 // Set the google base url. |base_url| must be valid. | 54 // Set the google base url. |base_url| must be valid. |
| 62 void SetGoogleBaseURL(const GURL& base_url) const; | 55 void SetGoogleBaseURL(const GURL& base_url); |
| 63 | 56 |
| 64 // Set the managed preferences for the default search provider and trigger | 57 // Set the managed preferences for the default search provider and trigger |
| 65 // notification. If |alternate_url| is empty, uses an empty list of alternate | 58 // notification. If |alternate_url| is empty, uses an empty list of alternate |
| 66 // URLs, otherwise use a list containing a single entry. | 59 // URLs, otherwise use a list containing a single entry. |
| 67 void SetManagedDefaultSearchPreferences( | 60 void SetManagedDefaultSearchPreferences( |
| 68 bool enabled, | 61 bool enabled, |
| 69 const std::string& name, | 62 const std::string& name, |
| 70 const std::string& keyword, | 63 const std::string& keyword, |
| 71 const std::string& search_url, | 64 const std::string& search_url, |
| 72 const std::string& suggest_url, | 65 const std::string& suggest_url, |
| 73 const std::string& icon_url, | 66 const std::string& icon_url, |
| 74 const std::string& encodings, | 67 const std::string& encodings, |
| 75 const std::string& alternate_url, | 68 const std::string& alternate_url, |
| 76 const std::string& search_terms_replacement_key); | 69 const std::string& search_terms_replacement_key); |
| 77 | 70 |
| 78 // Remove all the managed preferences for the default search provider and | 71 // Remove all the managed preferences for the default search provider and |
| 79 // trigger notification. | 72 // trigger notification. |
| 80 void RemoveManagedDefaultSearchPreferences(); | 73 void RemoveManagedDefaultSearchPreferences(); |
| 81 | 74 |
| 82 // Returns the TemplateURLService. | 75 // Returns the TemplateURLService. |
| 83 TemplateURLService* model() const; | 76 TemplateURLService* model(); |
| 84 | 77 |
| 85 // Returns the TestingProfile. | 78 // Returns the TestingProfile. |
| 86 virtual TestingProfile* profile() const = 0; | 79 TestingProfile* profile() { return profile_.get(); } |
| 87 | 80 |
| 88 private: | 81 private: |
| 89 int changed_count_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtilBase); | |
| 92 }; | |
| 93 | |
| 94 // TemplateURLServiceTestUtil sets up TestingProfile, TemplateURLService and | |
| 95 // required threads. | |
| 96 class TemplateURLServiceTestUtil : public TemplateURLServiceTestUtilBase { | |
| 97 public: | |
| 98 TemplateURLServiceTestUtil(); | |
| 99 virtual ~TemplateURLServiceTestUtil(); | |
| 100 | |
| 101 // Sets up the data structures for this class (mirroring gtest standard | |
| 102 // methods). | |
| 103 void SetUp(); | |
| 104 | |
| 105 // Cleans up data structures for this class (mirroring gtest standard | |
| 106 // methods). | |
| 107 void TearDown(); | |
| 108 | |
| 109 // Returns the TestingProfile. | |
| 110 virtual TestingProfile* profile() const OVERRIDE; | |
| 111 | |
| 112 private: | |
| 113 // Needed to make the DeleteOnUIThread trait of WebDataService work | |
| 114 // properly. | |
| 115 content::TestBrowserThreadBundle thread_bundle_; | 82 content::TestBrowserThreadBundle thread_bundle_; |
| 116 scoped_ptr<TestingProfile> profile_; | 83 scoped_ptr<TestingProfile> profile_; |
| 117 base::ScopedTempDir temp_dir_; | 84 base::ScopedTempDir temp_dir_; |
| 85 int changed_count_; |
| 86 scoped_ptr<TestingTemplateURLService> model_; |
| 118 | 87 |
| 119 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil); | 88 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil); |
| 120 }; | 89 }; |
| 121 | 90 |
| 122 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ | 91 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ |
| OLD | NEW |