summaryrefslogtreecommitdiffstats
path: root/components/search_engines/default_search_pref_test_util.h
blob: 53484e6a4a844aa0802c124920b4cef915c5bc6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_
#define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_

#include <string>

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "components/search_engines/default_search_manager.h"

class DefaultSearchPrefTestUtil {
 public:
  // Creates a DictionaryValue which can be used as a
  // kDefaultSearchProviderDataPrefName preference value.
  static scoped_ptr<base::DictionaryValue> CreateDefaultSearchPreferenceValue(
      bool enabled,
      const std::string& name,
      const std::string& keyword,
      const std::string& search_url,
      const std::string& suggest_url,
      const std::string& icon_url,
      const std::string& encodings,
      const std::string& alternate_url,
      const std::string& search_terms_replacement_key);

  // Set the managed preferences for the default search provider and trigger
  // notification. If |alternate_url| is empty, uses an empty list of alternate
  // URLs, otherwise use a list containing a single entry.
  template<typename TestingPrefService>
  static void SetManagedPref(TestingPrefService* pref_service,
                             bool enabled,
                             const std::string& name,
                             const std::string& keyword,
                             const std::string& search_url,
                             const std::string& suggest_url,
                             const std::string& icon_url,
                             const std::string& encodings,
                             const std::string& alternate_url,
                             const std::string& search_terms_replacement_key) {
    pref_service->SetManagedPref(
        DefaultSearchManager::kDefaultSearchProviderDataPrefName,
        CreateDefaultSearchPreferenceValue(
            enabled, name, keyword, search_url, suggest_url, icon_url,
            encodings, alternate_url, search_terms_replacement_key).release());
  }

  // Remove all the managed preferences for the default search provider and
  // trigger notification.
  template<typename TestingPrefService>
  static void RemoveManagedPref(TestingPrefService* pref_service) {
    pref_service->RemoveManagedPref(
        DefaultSearchManager::kDefaultSearchProviderDataPrefName);
  }
};

#endif  // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_