Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / chromeos / login / test / js_checker.h
blob2dd524ffa5e41b663dd200bb0a73adee56023d5e
1 // Copyright 2013 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_CHROMEOS_LOGIN_TEST_JS_CHECKER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_TEST_JS_CHECKER_H_
8 #include <string>
10 namespace content {
11 class WebContents;
14 namespace chromeos {
15 namespace test {
17 // Utility class for tests that allows us to evalute and check JavaScript
18 // expressions inside given web contents. All calls are made synchronously.
19 class JSChecker {
20 public:
21 JSChecker();
22 explicit JSChecker(content::WebContents* web_contents);
24 // Evaluates |expression|. Evaluation will be completed when this function
25 // call returns.
26 void Evaluate(const std::string& expression);
28 // Executes |expression|. Doesn't require a correct command. Command will be
29 // queued up and executed later. This function will return immediately.
30 void ExecuteAsync(const std::string& expression);
32 // Evaluates |expression| and returns its result.
33 bool GetBool(const std::string& expression);
34 int GetInt(const std::string& expression);
35 std::string GetString(const std::string& expression);
37 // Checks truthfulness of the given |expression|.
38 void ExpectTrue(const std::string& expression);
39 void ExpectFalse(const std::string& expression);
41 // Compares result of |expression| with |result|.
42 void ExpectEQ(const std::string& expression, int result);
43 void ExpectNE(const std::string& expression, int result);
44 void ExpectEQ(const std::string& expression, const std::string& result);
45 void ExpectNE(const std::string& expression, const std::string& result);
47 void set_web_contents(content::WebContents* web_contents) {
48 web_contents_ = web_contents;
51 private:
52 void GetBoolImpl(const std::string& expression, bool* result);
53 void GetIntImpl(const std::string& expression, int* result);
54 void GetStringImpl(const std::string& expression, std::string* result);
56 content::WebContents* web_contents_;
59 } // namespace test
60 } // namespace chromeos
62 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_TEST_JS_CHECKER_H_