finish WebView Tests

This commit is contained in:
andyque 2014-08-26 22:03:55 +08:00
parent 15815118a2
commit 9449152caf
7 changed files with 140 additions and 10 deletions

View File

@ -866,6 +866,7 @@
295824591987415900F9746D /* UIScale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 295824571987415900F9746D /* UIScale9SpriteTest.cpp */; }; 295824591987415900F9746D /* UIScale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 295824571987415900F9746D /* UIScale9SpriteTest.cpp */; };
2958245A1987415900F9746D /* UIScale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 295824571987415900F9746D /* UIScale9SpriteTest.cpp */; }; 2958245A1987415900F9746D /* UIScale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 295824571987415900F9746D /* UIScale9SpriteTest.cpp */; };
298D7F6F19AC31F300FF096D /* UIWebViewTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 298D7F6D19AC31F300FF096D /* UIWebViewTest.cpp */; }; 298D7F6F19AC31F300FF096D /* UIWebViewTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 298D7F6D19AC31F300FF096D /* UIWebViewTest.cpp */; };
29AFEF6719ACCAA000F6B10A /* Test.html in Resources */ = {isa = PBXBuildFile; fileRef = 29AFEF6619ACCAA000F6B10A /* Test.html */; };
29FBBBFE196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */; }; 29FBBBFE196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */; };
29FBBBFF196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */; }; 29FBBBFF196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */; };
38FA2E73194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 38FA2E71194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp */; }; 38FA2E73194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 38FA2E71194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp */; };
@ -2889,6 +2890,7 @@
295824581987415900F9746D /* UIScale9SpriteTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScale9SpriteTest.h; sourceTree = "<group>"; }; 295824581987415900F9746D /* UIScale9SpriteTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScale9SpriteTest.h; sourceTree = "<group>"; };
298D7F6D19AC31F300FF096D /* UIWebViewTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UIWebViewTest.cpp; path = UIWebViewTest/UIWebViewTest.cpp; sourceTree = "<group>"; }; 298D7F6D19AC31F300FF096D /* UIWebViewTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UIWebViewTest.cpp; path = UIWebViewTest/UIWebViewTest.cpp; sourceTree = "<group>"; };
298D7F6E19AC31F300FF096D /* UIWebViewTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIWebViewTest.h; path = UIWebViewTest/UIWebViewTest.h; sourceTree = "<group>"; }; 298D7F6E19AC31F300FF096D /* UIWebViewTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIWebViewTest.h; path = UIWebViewTest/UIWebViewTest.h; sourceTree = "<group>"; };
29AFEF6619ACCAA000F6B10A /* Test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = Test.html; path = "../tests/cpp-tests/Resources/Test.html"; sourceTree = "<group>"; };
29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocostudioParserJsonTest.cpp; sourceTree = "<group>"; }; 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocostudioParserJsonTest.cpp; sourceTree = "<group>"; };
29FBBBFD196A9ECD00E65826 /* CocostudioParserJsonTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocostudioParserJsonTest.h; sourceTree = "<group>"; }; 29FBBBFD196A9ECD00E65826 /* CocostudioParserJsonTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocostudioParserJsonTest.h; sourceTree = "<group>"; };
38FA2E71194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActionTimelineTestScene.cpp; sourceTree = "<group>"; }; 38FA2E71194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActionTimelineTestScene.cpp; sourceTree = "<group>"; };
@ -6498,6 +6500,7 @@
1AC35CB518CED84500F37B72 /* effect1.raw */, 1AC35CB518CED84500F37B72 /* effect1.raw */,
1AC35CB618CED84500F37B72 /* effect1.wav */, 1AC35CB618CED84500F37B72 /* effect1.wav */,
1AC35CC418CED84500F37B72 /* pew-pew-lei.wav */, 1AC35CC418CED84500F37B72 /* pew-pew-lei.wav */,
29AFEF6619ACCAA000F6B10A /* Test.html */,
); );
name = Resources; name = Resources;
sourceTree = "<group>"; sourceTree = "<group>";
@ -7829,6 +7832,7 @@
1AC35D0918CED84500F37B72 /* TileMaps in Resources */, 1AC35D0918CED84500F37B72 /* TileMaps in Resources */,
1AC35CFF18CED84500F37B72 /* Particles in Resources */, 1AC35CFF18CED84500F37B72 /* Particles in Resources */,
1AC35C8818CECF1400F37B72 /* Default-568h@2x.png in Resources */, 1AC35C8818CECF1400F37B72 /* Default-568h@2x.png in Resources */,
29AFEF6719ACCAA000F6B10A /* Test.html in Resources */,
1AC35CD518CED84500F37B72 /* ccb in Resources */, 1AC35CD518CED84500F37B72 /* ccb in Resources */,
1AC35CE118CED84500F37B72 /* configs in Resources */, 1AC35CE118CED84500F37B72 /* configs in Resources */,
1AC35CE918CED84500F37B72 /* extensions in Resources */, 1AC35CE918CED84500F37B72 /* extensions in Resources */,

View File

@ -167,9 +167,9 @@ private:
WebViewImpl *_impl; WebViewImpl *_impl;
}; };
} // namespace cocos2d } // namespace ui
} // namespace experimental } // namespace experimental
}//namespace ui }//namespace cocos2d
#endif #endif

View File

@ -84,8 +84,8 @@ private:
WebView *_webView; WebView *_webView;
}; };
} // namespace cocos2d } // namespace ui
} // namespace experimental } // namespace experimental
}//namespace ui }//namespace cocos2d
#endif //__cocos2d_plugin_WebViewImpl_IOS_H_ #endif //__cocos2d_plugin_WebViewImpl_IOS_H_

View File

@ -96,6 +96,7 @@
} }
- (void)dealloc { - (void)dealloc {
self.uiWebView.delegate = nil;
[self.uiWebView removeFromSuperview]; [self.uiWebView removeFromSuperview];
self.jsScheme = nil; self.jsScheme = nil;
[super dealloc]; [super dealloc];
@ -343,8 +344,8 @@ void WebViewImpl::setVisible(bool visible){
[_uiWebViewWrapper setVisible:visible]; [_uiWebViewWrapper setVisible:visible];
} }
} // namespace cocos2d } // namespace ui
} // namespace experimental } // namespace experimental
} //namespace ui } //namespace cocos2d
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_IOS #endif // CC_TARGET_PLATFORM == CC_PLATFORM_IOS

View File

@ -37,14 +37,132 @@ WebViewTest::~WebViewTest()
bool WebViewTest::init() bool WebViewTest::init()
{ {
if (UIScene::init()) { if (UIScene::init()) {
Size winSize = Director::getInstance()->getVisibleSize();
_webView = cocos2d::experimental::ui::WebView::create(); _webView = cocos2d::experimental::ui::WebView::create();
_webView->setPosition(Director::getInstance()->getVisibleSize()/2); _webView->setPosition(winSize/2);
_webView->setContentSize(Director::getInstance()->getVisibleSize() * 0.5); _webView->setContentSize(winSize * 0.5);
_webView->loadUrl("http://www.baidu.com"); _webView->loadUrl("http://www.google.com");
_webView->setScalesPageToFit(true); _webView->setScalesPageToFit(true);
_webView->shouldStartLoading = CC_CALLBACK_2(WebViewTest::onWebViewShouldStartLoading, this);
_webView->didFinishLoading = CC_CALLBACK_2(WebViewTest::onWebViewDidFinishLoading, this);
_webView->didFailLoading = CC_CALLBACK_2(WebViewTest::onWebViewDidFailLoading, this);
this->addChild(_webView); this->addChild(_webView);
TextField *urlTextField = TextField::create("Input a URL here", "Arial", 20);
urlTextField->setPlaceHolderColor(Color3B::RED);
urlTextField->setPosition(Vec2(winSize/2) + Vec2(-80, _webView->getContentSize().height/2 +
urlTextField->getContentSize().height/2 + 10));
this->addChild(urlTextField);
Text *httpLabel = Text::create("http:// ", "Arial", 20);
httpLabel->setTextColor(Color4B::GREEN);
httpLabel->setAnchorPoint(Vec2(1.0,0.5));
httpLabel->setPosition(urlTextField->getPosition() - Vec2(urlTextField->getContentSize().width/2,0));
this->addChild(httpLabel);
Button *resetBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
resetBtn->setTitleText("Visit URL");
resetBtn->setPosition(Vec2(winSize/2) + Vec2(50, _webView->getContentSize().height/2 +
resetBtn->getContentSize().height/2 + 10));
resetBtn->addClickEventListener([=](Ref*){
_webView->loadUrl(std::string("http://") + urlTextField->getStringValue());
});
this->addChild(resetBtn);
Button *reloadBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
reloadBtn->setTitleText("Reload");
reloadBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
reloadBtn->getContentSize().width/2 + 10,50 ));
reloadBtn->addClickEventListener([=](Ref*){
_webView->reload();
});
this->addChild(reloadBtn);
Button *forwardBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
forwardBtn->setTitleText("Forward");
forwardBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
forwardBtn->getContentSize().width/2 + 10,0 ));
forwardBtn->addClickEventListener([=](Ref*){
_webView->goForward();
});
this->addChild(forwardBtn);
Button *backBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
backBtn->setTitleText("Back");
backBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
backBtn->getContentSize().width/2 + 10,-50 ));
backBtn->addClickEventListener([=](Ref*){
_webView->goBack();
});
this->addChild(backBtn);
Button *loadFileBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
loadFileBtn->setTitleText("Load FILE");
loadFileBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
loadFileBtn->getContentSize().width/2 + 10,50 ));
loadFileBtn->addClickEventListener([=](Ref*){
_webView->loadFile("Test.html");
});
this->addChild(loadFileBtn);
Button *loadHTMLBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
loadHTMLBtn->setTitleText("Load HTML");
loadHTMLBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
loadHTMLBtn->getContentSize().width/2 + 10,0 ));
loadHTMLBtn->addClickEventListener([=](Ref*){
_webView->loadHTMLString("<body style=\"font-size:50px;\">Hello World</body>","");
});
this->addChild(loadHTMLBtn);
Button *evalJsBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
evalJsBtn->setTitleText("Evaluate JS");
evalJsBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
evalJsBtn->getContentSize().width/2 + 10,-50 ));
evalJsBtn->addClickEventListener([=](Ref*){
_webView->evaluateJS("alert(\"hello\")");
});
this->addChild(evalJsBtn);
return true; return true;
} }
return false; return false;
} }
bool WebViewTest::onWebViewShouldStartLoading(experimental::ui::WebView *sender, std::string url)
{
CCLOG("onWebViewShouldStartLoading, url is %s", url.c_str());
return true;
}
void WebViewTest::onWebViewDidFinishLoading(experimental::ui::WebView *sender, std::string url)
{
CCLOG("onWebViewDidFinishLoading, url is %s", url.c_str());
}
void WebViewTest::onWebViewDidFailLoading(experimental::ui::WebView *sender, std::string url)
{
CCLOG("onWebViewDidFailLoading, url is %s", url.c_str());
}

View File

@ -37,8 +37,10 @@ public:
UI_SCENE_CREATE_FUNC(WebViewTest); UI_SCENE_CREATE_FUNC(WebViewTest);
virtual bool init(); virtual bool init();
bool onWebViewShouldStartLoading(experimental::ui::WebView *sender, std::string url);
void onWebViewDidFinishLoading(experimental::ui::WebView *sender, std::string url);
void onWebViewDidFailLoading(experimental::ui::WebView *sender, std::string url);
private: private:
cocos2d::experimental::ui::WebView *_webView; cocos2d::experimental::ui::WebView *_webView;

View File

@ -0,0 +1,5 @@
<html>
<body style="font-size:100px;">
Hello World
</body>
</html>