BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / translate / cld_data_harness.h
blob6a78d78d8142d4152af44621829616abc3a623fd
1 // Copyright 2014 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_TRANSLATE_CLD_DATA_HARNESS_H_
6 #define CHROME_BROWSER_TRANSLATE_CLD_DATA_HARNESS_H_
8 #include "base/files/file_path.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
12 namespace test {
14 // A utility class that sets up CLD dynamic data upon calling Init() and cleans
15 // it up when destroyed. Note that the Init() method will also configure the
16 // CLD data source using translate::CldDataSource::Set(), overriding any
17 // previously-set value unconditionally!
19 // Test data lives under: src/chrome/test/data/cld2_component
21 // This class is intended to be instantiated within IN_PROC_BROWSER_TEST_F
22 // test fixtures; it uses ASSERT macros for correctness, so that tests will
23 // fail gracefully in error conditions. Test code should generally use a
24 // CldDataHarnessFactory to create CldDataHarness objects since this allows
25 // the tests to run with whatever configuration is appropriate for the platform;
26 // If that's not enough power, the testing code can set the factory itself.
28 // Sample usage:
30 // IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) {
31 // scoped_ptr<test::CldDataHarness> cld_data_scope =
32 // test::CldDataHarnessFactory::Get()->CreateCldDataHarness();
33 // ASSERT_NO_FATAL_FAILURE(cld_data_scope->Init());
34 // // ... your code that depends on language detection goes here
35 // }
37 // If you have a lot of tests that need language translation features, you can
38 // add an instance of the CldDataHarness to your test class' private
39 // member variables and add the call to Init() into SetUpOnMainThread.
40 // Sample use:
42 // class MyTestClass : public InProcessBrowserTest {
43 // public:
44 // MyTestClass() :
45 // cld_data_scope(
46 // test::CldDataHarnessFactory::Get->CreateCldDataHarness()) {
47 // // (your additional setup code here)
48 // }
49 // void SetUpOnMainThread() override {
50 // cld_data_scope->Init();
51 // InProcessBrowserTest::SetUpOnMainThread();
52 // }
53 // private:
54 // scoped_ptr<test::CldDataHarness> cld_data_scope;
55 // };
57 class CldDataHarness {
58 public:
59 CldDataHarness() {}
61 // Reverses the work done by the Init() method: any files and/or directories
62 // that would be created by Init() (whether it was called or not) are
63 // immediately deleted.
64 // If dynamic data is not currently available for any reason, this method has
65 // no effect.
66 // The default implementation does nothing.
67 virtual ~CldDataHarness() {}
69 // Call this method, wrapping it in ASSERT_NO_FATAL_FAILURE, to initialize
70 // the harness and trigger test failure if initialization fails.
71 // IMPORTANT: This method will unconditionally set the CLD data source using
72 // translate::CldDataSource::Set(...). Any previously-configured CLD data
73 // source will be lost. This helps ensure a consistent test environment where
74 // the configured data source matches definitely matches the harness.
75 virtual void Init() {}
77 // Create and return a new instance of a data harness whose Init() method
78 // will configure the "static" CldDataSource.
79 static scoped_ptr<CldDataHarness> CreateStaticDataHarness();
81 // Create and return a new instance of a data harness whose Init() method
82 // will configure the "standalone" CldDataSource.
83 // Unlike NONE() and STATIC(), this data hardness will perform work to allow
84 // CLD to load data from a file.
85 static scoped_ptr<CldDataHarness> CreateStandaloneDataHarness();
87 // Create and return a new instance of a data harness whose Init() method
88 // will configure the "component" CldDataSource.
89 // Unlike NONE() and STATIC(), this data hardness will perform work to allow
90 // CLD to load data from a file.
91 static scoped_ptr<CldDataHarness> CreateComponentDataHarness();
93 protected:
94 // Returns the version number of the Component Updater "extension" in the
95 // test directory. This generally corresponds the the revision of CLD2 that
96 // the data was built from. The version number is also part of the path that
97 // would be present at runtime if the component installer was used as the
98 // CLD2 data source.
99 const base::FilePath::CharType* GetTestDataSourceCrxVersion();
101 // Returns the path to the Component Updater "extension" files in the test
102 // directory. Within, there is a real copy of the CLD2 dynamic data that can
103 // be used in testing scenarios without accessing the network.
104 void GetTestDataSourceDirectory(base::FilePath* out_path);
106 private:
107 DISALLOW_COPY_AND_ASSIGN(CldDataHarness);
110 } // namespace test
112 #endif // CHROME_BROWSER_TRANSLATE_CLD_DATA_HARNESS_H_