spec/unit/web_spec.rb in ProMotion-2.8.2 vs spec/unit/web_spec.rb in ProMotion-3.0.0
- old
+ new
@@ -1,114 +1,136 @@
describe "web screen properties" do
- extend WebStub::SpecHelpers
+ # NOTE: webstub doesn't work with WKWebView
+ # extend WebStub::SpecHelpers
+ # before { disable_network_access! }
+ # after { enable_network_access! }
- before { disable_network_access! }
- after { enable_network_access! }
-
it "should leave on_init available as a hook" do
- webscreen = TestWebScreen.new()
+ webscreen = TestWebScreen.new
webscreen.on_init_available?.should == true
end
- describe "when open web page with http request" do
+ it "can perform asynchronous javascript execution" do
+ webscreen = TestWebScreen.new
+ js = 'document.documentElement.innerHTML = "test"; document.documentElement.outerHTML'
+ webscreen.evaluate_async(js) do |result, error|
+ result.should == '<html><head></head><body>test</body></html>'
+ resume
+ end
+ wait_max 2 {}
+ end
+
+ it "can perform synchronous javascript execution" do
+ webscreen = TestWebScreen.new
+ js = 'document.documentElement.innerHTML = "test"; document.documentElement.outerHTML'
+ wait_max(2) do
+ result = webscreen.evaluate(js)
+ result.should == '<html><head></head><body>test</body></html>'
+ end
+ end
+
+ describe "opening a web page using an http request" do
before do
class TestWebScreenWithHTTPRequest < TestWebScreen
- attr_accessor :on_request, :on_request_args
+ attr_accessor :on_request_called, :on_request_args
+ # NOTE: this hook is for deciding whether or not the request should continue
def on_request(request, type)
self.on_request_args = [request, type]
- self.on_request = true
+ self.on_request_called = true
+ false # cancel request since we can't stub it
end
end
- stub_request(:get, "http://mixi.jp/").
- to_return(body: "<html><body>[mixi]</body></html>", content_type: "text/html")
+
+ # NOTE: webstub doesn't support stubbing WKWebView requests
+ #stub_request(:get, "https://mixi.jp/").
+ # to_return(body: "<html><body>[mixi]</body></html>", content_type: "text/html")
+
# Simulate AppDelegate setup of web screen
@webscreen = TestWebScreenWithHTTPRequest.new modal: true, nav_bar: true, external_links: false
end
+
+ it "should call on_request hook" do
+ @webscreen.open_url('https://mixi.jp/')
- it "should get the current url" do
- @webscreen.open_url(NSURL.URLWithString('http://mixi.jp/'))
-
- wait_for_change @webscreen, 'is_load_finished' do
- @webscreen.current_url.should == 'http://mixi.jp/'
+ wait_for_change @webscreen, 'on_request_called' do
+ @webscreen.on_request_called.should == true
end
end
it "should open web page via NSMutableURLRequest" do
- nsurl = NSURL.URLWithString('http://mixi.jp/')
+ nsurl = NSURL.URLWithString('https://mixi.jp/')
@webscreen.web.loadRequest NSMutableURLRequest.requestWithURL(nsurl)
- wait_for_change @webscreen, 'is_load_finished' do
- @webscreen.current_url.should == 'http://mixi.jp/'
+ wait_for_change @webscreen, 'on_request_called' do
+ request = @webscreen.on_request_args.first
+ request.should.be.a.kind_of NSURLRequest
+ request.URL.absoluteString.should == 'https://mixi.jp/'
end
end
it "should open web page by url string" do
- @webscreen.open_url('http://mixi.jp/')
- wait_for_change @webscreen, 'is_load_finished' do
- @webscreen.html.should =~ /mixi/
- end
- end
+ @webscreen.open_url('https://mixi.jp/')
- it "should call on_request hook" do
- @webscreen.open_url(NSURL.URLWithString('http://mixi.jp/'))
-
- wait_for_change @webscreen, 'on_request' do
- @webscreen.on_request_args[0].is_a?(NSURLRequest).should == true
- # on_request is called when @webscreen request for some iframe
- @webscreen.on_request_args[0].URL.absoluteString.should =~ %r|https?://.*|
+ wait_for_change @webscreen, 'on_request_called' do
+ request = @webscreen.on_request_args.first
+ request.should.be.a.kind_of NSURLRequest
+ request.URL.absoluteString.should == 'https://mixi.jp/'
end
end
+ # TODO: these features used to be supported prior to WKWebView migration
+ # it "can synchronously return the current page html"
+ # it "can synchronously return the current page url"
end
describe "when loading a static html file" do
before do
# Simulate AppDelegate setup of web screen
@webscreen = TestWebScreen.new modal: true, nav_bar: true, external_links: false
@webscreen.set_content("WebScreen.html")
end
it "should get the url of content" do
- @webscreen.current_url.should == 'about:blank'
+ @webscreen.current_url do |url|
+ url.should == 'about:blank'
+ resume
+ end
+ wait_max 1 {}
end
- it "should have a UIWebView as the primary view" do
- @webscreen.web.class.should == UIWebView
+ it "should have a WKWebView as the primary view" do
+ @webscreen.web.class.should == WKWebView
end
it "should load the about html page" do
- wait_for_change @webscreen, 'is_load_finished' do
- @webscreen.is_load_finished.should == true
+ wait_for_change @webscreen, 'is_nav_finished', 3 do
+ @webscreen.is_nav_finished.should == true
end
end
end
describe "when setting attributes" do
it "should have a default values" do
webscreen = TestWebScreen.new()
- webscreen.web.dataDetectorTypes.should == UIDataDetectorTypeNone
- webscreen.web.scalesPageToFit.should == false
+ webscreen.web.configuration.dataDetectorTypes.should == UIDataDetectorTypeNone
webscreen.external_links.should == false
end
- it "should set a single data detector" do
- webscreen = TestWebScreen.new(detector_types: :phone)
- webscreen.web.dataDetectorTypes.should == UIDataDetectorTypePhoneNumber
- end
+# FIXME: these should work after getting initWithFrame:configuration: to work.
+# it "should set a single data detector" do
+# webscreen = TestWebScreen.new(detector_types: :phone)
+# webscreen.web.configuration.dataDetectorTypes.should == UIDataDetectorTypePhoneNumber
+# end
- it "should set multiple data detectors" do
- webscreen = TestWebScreen.new(detector_types: [:phone, :link])
- webscreen.web.dataDetectorTypes.should == UIDataDetectorTypePhoneNumber | UIDataDetectorTypeLink
- end
+# it "should set multiple data detectors" do
+# webscreen = TestWebScreen.new(detector_types: [:phone, :link])
+# webscreen.web.configuration.dataDetectorTypes.should == UIDataDetectorTypePhoneNumber | UIDataDetectorTypeLink
+# end
- it "should set the scaling mode of the screen" do
- webscreen = TestWebScreen.new(scale_to_fit: true)
- webscreen.web.scalesPageToFit.should == true
- end
-
it "should have the ability to open links externally" do
webscreen = TestWebScreen.new(external_links: true)
webscreen.external_links.should == true
+ # TODO: test that link click opens Safari
end
end
end