template_url_service_test_util.h revision 116680a4aac90f2aa7413d9095a592090648e557
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.
4
5#ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_
6#define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/files/scoped_temp_dir.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/strings/string16.h"
14#include "components/search_engines/template_url_service_observer.h"
15#include "content/public/test/test_browser_thread_bundle.h"
16
17class GURL;
18class TemplateURLService;
19class TestingProfile;
20class TestingTemplateURLService;
21
22class TemplateURLServiceTestUtil : public TemplateURLServiceObserver {
23 public:
24  TemplateURLServiceTestUtil();
25  virtual ~TemplateURLServiceTestUtil();
26
27  // TemplateURLServiceObserver implemementation.
28  virtual void OnTemplateURLServiceChanged() OVERRIDE;
29
30  // Gets the observer count.
31  int GetObserverCount();
32
33  // Sets the observer count to 0.
34  void ResetObserverCount();
35
36  // Makes sure the load was successful and sent the correct notification.
37  void VerifyLoad();
38
39  // Makes the model believe it has been loaded (without actually doing the
40  // load). Since this avoids setting the built-in keyword version, the next
41  // load will do a merge from prepopulated data.
42  void ChangeModelToLoadState();
43
44  // Deletes the current model (and doesn't create a new one).
45  void ClearModel();
46
47  // Creates a new TemplateURLService.
48  void ResetModel(bool verify_load);
49
50  // Returns the search term from the last invocation of
51  // TemplateURLService::SetKeywordSearchTermsForURL and clears the search term.
52  base::string16 GetAndClearSearchTerm();
53
54  // Set the google base url.  |base_url| must be valid.
55  void SetGoogleBaseURL(const GURL& base_url);
56
57  // Set the managed preferences for the default search provider and trigger
58  // notification. If |alternate_url| is empty, uses an empty list of alternate
59  // URLs, otherwise use a list containing a single entry.
60  void SetManagedDefaultSearchPreferences(
61      bool enabled,
62      const std::string& name,
63      const std::string& keyword,
64      const std::string& search_url,
65      const std::string& suggest_url,
66      const std::string& icon_url,
67      const std::string& encodings,
68      const std::string& alternate_url,
69      const std::string& search_terms_replacement_key);
70
71  // Remove all the managed preferences for the default search provider and
72  // trigger notification.
73  void RemoveManagedDefaultSearchPreferences();
74
75  // Returns the TemplateURLService.
76  TemplateURLService* model();
77
78  // Returns the TestingProfile.
79  TestingProfile* profile() { return profile_.get(); }
80
81 private:
82  content::TestBrowserThreadBundle thread_bundle_;
83  scoped_ptr<TestingProfile> profile_;
84  base::ScopedTempDir temp_dir_;
85  int changed_count_;
86  scoped_ptr<TestingTemplateURLService> model_;
87
88  DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil);
89};
90
91#endif  // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_
92