Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(845)

Side by Side Diff: ios/web/public/test/web_js_test.h

Issue 2148873003: Reland: Improve ios/web/public/test/web_js_test.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ASSERT instead of EXPECT Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IOS_INTERNAL_CHROME_BROWSER_WEB_WEB_JS_TEST_H_ 5 #ifndef IOS_INTERNAL_CHROME_BROWSER_WEB_WEB_JS_TEST_H_
6 #define IOS_INTERNAL_CHROME_BROWSER_WEB_WEB_JS_TEST_H_ 6 #define IOS_INTERNAL_CHROME_BROWSER_WEB_WEB_JS_TEST_H_
7 7
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 9
10 #import "base/mac/bundle_locations.h" 10 #import "base/mac/bundle_locations.h"
11 #import "base/mac/scoped_nsobject.h" 11 #import "base/mac/scoped_nsobject.h"
12 #include "testing/gtest_mac.h" 12 #include "testing/gtest_mac.h"
13 13
14 class GURL; 14 class GURL;
15 15
16 namespace web { 16 namespace web {
17 17
18 // Base fixture mixin for testing JavaScripts. 18 // Base fixture mixin for testing JavaScripts.
19 template <class WebTestT> 19 template <class WebTestT>
20 class WebJsTest : public WebTestT { 20 class WebJsTest : public WebTestT {
21 public: 21 public:
22 WebJsTest(NSArray* java_script_paths) 22 WebJsTest(NSArray* java_script_paths)
23 : java_script_paths_([java_script_paths retain]) {} 23 : java_script_paths_([java_script_paths copy]) {}
24 24
25 protected: 25 protected:
26 // Loads |html| and inject JavaScripts at |javaScriptPaths_|. 26 // Loads |html| and inject JavaScripts at |javaScriptPaths_|.
27 void LoadHtmlAndInject(NSString* html) { 27 void LoadHtmlAndInject(NSString* html) {
28 WebTestT::LoadHtml(html); 28 WebTestT::LoadHtml(html);
29 Inject(); 29 Inject();
30 } 30 }
31 31
32 // Returns a NSString representation of the JavaScript's evaluation results; 32 // Returns a NSString representation of the JavaScript's evaluation results;
33 // the JavaScript is passed in as a |format| and its arguments. 33 // the JavaScript is passed in as a |format| and its arguments.
(...skipping 19 matching lines...) Expand all
53 53
54 private: 54 private:
55 // Injects JavaScript at |java_script_paths_|. 55 // Injects JavaScript at |java_script_paths_|.
56 void Inject(); 56 void Inject();
57 57
58 base::scoped_nsobject<NSArray> java_script_paths_; 58 base::scoped_nsobject<NSArray> java_script_paths_;
59 }; 59 };
60 60
61 template <class WebTestT> 61 template <class WebTestT>
62 void WebJsTest<WebTestT>::Inject() { 62 void WebJsTest<WebTestT>::Inject() {
63 // Wait until main web injection has occured. 63 // Main web injection should have occured.
64 NSString* beacon = nil; 64 ASSERT_NSEQ(@"object",
65 do { 65 WebTestT::EvaluateJavaScriptAsString(@"typeof __gCrWeb"));
66 beacon = WebTestT::EvaluateJavaScriptAsString(@"typeof __gCrWeb"); 66
67 } while (![beacon isEqualToString:@"object"]);
68 for (NSString* java_script_path in java_script_paths_.get()) { 67 for (NSString* java_script_path in java_script_paths_.get()) {
69 NSString* path = 68 NSString* path =
70 [base::mac::FrameworkBundle() pathForResource:java_script_path 69 [base::mac::FrameworkBundle() pathForResource:java_script_path
71 ofType:@"js"]; 70 ofType:@"js"];
72 WebTestT::EvaluateJavaScriptAsString([NSString 71 WebTestT::EvaluateJavaScriptAsString([NSString
73 stringWithContentsOfFile:path 72 stringWithContentsOfFile:path
74 encoding:NSUTF8StringEncoding 73 encoding:NSUTF8StringEncoding
75 error:nil]); 74 error:nil]);
76 } 75 }
77 } 76 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 EXPECT_NSEQ(expected, EvaluateJavaScriptWithFormat(java_script, 113 EXPECT_NSEQ(expected, EvaluateJavaScriptWithFormat(java_script,
115 get_element_java_script)) 114 get_element_java_script))
116 << [NSString stringWithFormat:@"%@ on %@ should return %@", java_script, 115 << [NSString stringWithFormat:@"%@ on %@ should return %@", java_script,
117 get_element_java_script, expected]; 116 get_element_java_script, expected];
118 } 117 }
119 } 118 }
120 119
121 } // namespace web 120 } // namespace web
122 121
123 #endif // IOS_INTERNAL_CHROME_BROWSER_WEB_WEB_JS_TEST_H_ 122 #endif // IOS_INTERNAL_CHROME_BROWSER_WEB_WEB_JS_TEST_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698