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. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_TEST_JS_CHECKER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_TEST_JS_CHECKER_H_ 7 8 #include <string> 9 10 namespace content { 11 class WebContents; 12 } 13 14 namespace chromeos { 15 namespace test { 16 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); 23 24 // Evaluates |expression|. 25 void Evaluate(const std::string& expression); 26 27 // Evaluates |expression| and returns its result. 28 bool GetBool(const std::string& expression); 29 int GetInt(const std::string& expression); 30 std::string GetString(const std::string& expression); 31 32 // Checks truthfulness of the given |expression|. 33 void ExpectTrue(const std::string& expression); 34 void ExpectFalse(const std::string& expression); 35 36 // Compares result of |expression| with |result|. 37 void ExpectEQ(const std::string& expression, int result); 38 void ExpectNE(const std::string& expression, int result); 39 void ExpectEQ(const std::string& expression, const std::string& result); 40 void ExpectNE(const std::string& expression, const std::string& result); 41 set_web_contents(content::WebContents * web_contents)42 void set_web_contents(content::WebContents* web_contents) { 43 web_contents_ = web_contents; 44 } 45 46 private: 47 void GetBoolImpl(const std::string& expression, bool* result); 48 void GetIntImpl(const std::string& expression, int* result); 49 void GetStringImpl(const std::string& expression, std::string* result); 50 51 content::WebContents* web_contents_; 52 }; 53 54 } // namespace test 55 } // namespace chromeos 56 57 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_TEST_JS_CHECKER_H_ 58