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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_
10 #include "base/basictypes.h"
11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string16.h"
16 #include "chrome/browser/search_engines/template_url_service_observer.h"
17 #include "chrome/test/base/testing_browser_process.h"
18 #include "content/public/test/test_browser_thread_bundle.h"
21 class TemplateURLService
;
23 class TestingTemplateURLService
;
27 // TemplateURLServiceTestUtilBase contains basic API to ease testing of
28 // TemplateURLService. User should take care of the infrastructure separately.
29 class TemplateURLServiceTestUtilBase
: public TemplateURLServiceObserver
{
31 TemplateURLServiceTestUtilBase();
32 virtual ~TemplateURLServiceTestUtilBase();
34 void CreateTemplateUrlService();
36 // TemplateURLServiceObserver implemementation.
37 virtual void OnTemplateURLServiceChanged() OVERRIDE
;
39 // Gets the observer count.
40 int GetObserverCount();
42 // Sets the observer count to 0.
43 void ResetObserverCount();
45 // Makes sure the load was successful and sent the correct notification.
48 // Makes the model believe it has been loaded (without actually doing the
49 // load). Since this avoids setting the built-in keyword version, the next
50 // load will do a merge from prepopulated data.
51 void ChangeModelToLoadState();
53 // Deletes the current model (and doesn't create a new one).
56 // Creates a new TemplateURLService.
57 void ResetModel(bool verify_load
);
59 // Returns the search term from the last invocation of
60 // TemplateURLService::SetKeywordSearchTermsForURL and clears the search term.
61 base::string16
GetAndClearSearchTerm();
63 // Set the google base url. |base_url| must be valid.
64 void SetGoogleBaseURL(const GURL
& base_url
) const;
66 // Set the managed preferences for the default search provider and trigger
67 // notification. If |alternate_url| is empty, uses an empty list of alternate
68 // URLs, otherwise use a list containing a single entry.
69 void SetManagedDefaultSearchPreferences(
71 const std::string
& name
,
72 const std::string
& keyword
,
73 const std::string
& search_url
,
74 const std::string
& suggest_url
,
75 const std::string
& icon_url
,
76 const std::string
& encodings
,
77 const std::string
& alternate_url
,
78 const std::string
& search_terms_replacement_key
);
80 // Remove all the managed preferences for the default search provider and
81 // trigger notification.
82 void RemoveManagedDefaultSearchPreferences();
84 // Returns the TemplateURLService.
85 TemplateURLService
* model() const;
87 // Returns the TestingProfile.
88 virtual TestingProfile
* profile() const = 0;
93 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtilBase
);
96 // TemplateURLServiceTestUtil sets up TestingProfile, TemplateURLService and
98 class TemplateURLServiceTestUtil
: public TemplateURLServiceTestUtilBase
{
100 TemplateURLServiceTestUtil();
101 virtual ~TemplateURLServiceTestUtil();
103 // Sets up the data structures for this class (mirroring gtest standard
107 // Cleans up data structures for this class (mirroring gtest standard
111 // Returns the TestingProfile.
112 virtual TestingProfile
* profile() const OVERRIDE
;
115 // Needed to make the DeleteOnUIThread trait of WebDataService work
117 content::TestBrowserThreadBundle thread_bundle_
;
118 scoped_ptr
<TestingProfile
> profile_
;
119 base::ScopedTempDir temp_dir_
;
121 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil
);
124 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_