Test version of GWT DOM - unit-testing

Does anybody know any libraries which allow to create GWT DOM tree without having a browser running. I need this for fast test. It seems to me that DOM classes contain a lot of native methods, which are almost impossible to mock.

Phantom JS may be suitable for your task. It runs WebKit in memory without any graphical interface so it works much faster then the "normal" browser.

Searching other stuff on internet I found it. I have no idea if it works for you, if yes, share your experience because your topic is useful:
https://github.com/gwt-test-utils/gwt-test-utils/wiki/Browser-simulation

Related

Firefox extension and nsIMutationObserver

I am a Firefox C++ extension newbie. I need to get access to DOM mutation events in my extension during page load. Firefox by default doesn't send DOM mutation events during page load to improve page load performance.
I understand the reason, but understanding the consequences I still need access to the DOM mutation events. I read somewhere that nsIMutationObserver still gets invoked during page load (and is bit more efficient then DOM mutation events as don't have to walk up the DOM tree looking for listeners), however it's only available to native code.
So I have following questions :
Is nsIMutationObserver and nsIMutationObserver2 available to Firefox extensions?
If yes, how can I write a simple Firefox extension in C++ to get access to it and expose it to Javascript?
If folks can point me to a existing extension that does this forwarding from C++ land to JS, that will be highly appreciated.
Or can I use JS-CTypes to get access to that functionality from my Javascript based extension?
BTW, I asked this question in Firefox's extension forum, but no replies there.
Thanks in advance
Is nsIMutationObserver and nsIMutationObserver2 available to Firefox extensions?
Yes, binary Firefox extensions can use it. Of course, the drawback is that your binary XPCOM component will only work with one Firefox release - it will have to be recompiled for each new release.
If yes, how can I write a simple Firefox extension in C++ to get access to it and expose it to Javascript?
You create an XPCOM component (see example code) and implement nsIMutationObserver interface. You then attach this mutation observer to documents like this:
NS_IMETHODIMP
MyMutationObserver::AttachToDocument(nsIDOMDocument* document)
{
nsCOMPtr<nsINode> node(do_QueryInterface(document));
node->AddMutationObserver(this);
}
For reference: nsINode interface
If folks can point me to a existing extension that does this forwarding from C++ land to JS, that will be highly appreciated.
Sorry, don't know any. But your XPCOM component can expose an additional interface that your JavaScript code will use - e.g. to register a callback. You have to consider that it might not be safe to run JavaScript when the mutation observer gets called. Important methods here: nsContentUtils::IsSafeToRunScript() and nsContentUtils::AddScriptRunner() (see nsContentUtils.h).
Or can I use JS-CTypes to get access to that functionality from my Javascript based extension?
No, you cannot. These are Gecko internals, they aren't exposed to js-ctypes.
A binary extension can use nsIMutationObserver, but unless it's very very careful about what it does when it's notified (see the big WARNING above the interface declaration) it'll cause crashes and various other broken behavior and is likely to introduce security bugs. Like any other internal API, this is a footgun; probably a fatal one if not used extremely carefully. Things that are fine to do in a DOM mutation listener are NOT OK in an nsIMutationObserver.

Can I make a game using c++ that will run on the web?

There is some libraries that lets you run C++. So, it is it possible to run a game that uses directx full mode screen?
Google is developing a tool to allow this kind of thing via Chrome. It is called Chrome Native Client, or NACL for short. http://blog.chromium.org/2010/05/sneak-peek-at-native-client-sdk.html
In general, no. Most online games are written with Javascript, Flash, the newly hatchedd HTML5 and similar technologies. Perhaps C++ integration is possible on some level, but you definitely cannot write a browser-hosted game purely and entirely in C++.
it could also be done with an ActiveX control. ActiveX only works in IE. there are Netscape plugins that work in other browsers. so make a solution that contains both. you need a book on ActiveX/COM/OLE. Better yet, take a class if you can find one, you will learn far more, because COM is not an easy subject to just read about and then really do - versioning is a big problem.
nope, not supported in firefox. but read this: http://www.google.com/chrome/intl/en/webmasters-faq.html#activex
some people may have activex controls disabled. if this is the case, your game will not run. you will have to tell the user that they will need to change their security settings in IE. you can get feedback from the object element in javascript as to whether or not the activex loaded. there is code out there for that.
http://msdn.microsoft.com/en-us/library/7sw4ddf8%28v=vs.85%29.aspx
examples are all over the internet.

How to access DOM of a web page in QtWebKit?

How to access DOM of a web page in QtWebKit?
I don't see any methods exposing DOM in QtWebKit...
Currently, you need to do DOM manipulation via JavaScript, injected via
QVariant QWebFrame::evaluateJavaScript(const QString & scriptSource);
Right now as of Qt 4.4/4.5 I don't think there are any direct way, but it's coming. See http://labs.trolltech.com/blogs/2009/04/07/qwebelement-sees-the-light-do-i-hear-a-booyakasha/
the DOM manipulation via javascript method is incredibly poor. for any serious usage it very quickly becomes apparent that it is completely unusable. an experiment was made to create a runtime for pyjamas-desktop using pywebkitqt4 and it utterly, utterly failed. quite a lot was achieved - such as event callbacks written in python - but they had to be set up... by creating a javascript code-snippet! this approach is truly insane. every time you want to manipulate the DOM model from python you have to go via a crap language like javascript? anybody who thinks that's a good idea is completely off their heads.
fortunately at some point in the future i will be extending pythonwebkit to allow full access to DOM functions: it will be quite easy to do this, but i just don't have the time spare at the moment to compile up webkit for qt4 (it takes 90 mins for webkit with gtk as it is).

Browser agnostic C++ DOM interface

When programming in C++ against the browser's DOM each engine has a different set of interfaces, IE has the COM based [MSHTML](http://msdn.microsoft.com/en-us/library/aa752279(VS.85).aspx), Mozilla has the XPCOM based Gecko DOM etc.
Is there a common API that has adapters for major browsers (and versions)?
As a clarification, the application in question is a desktop application written in C++ which interacts with browsers, currently we have separate code bases for support of IE and Mozilla and I'm trying to reduce duplications of logic and allow adding new browsers with less effort.
A concrete example can be getting the innerHTML property of an HTML element.
// Firefox
nsAutoString html;
nsCOMPtr<nsIDOMNSHTMLElement> elem = do_QueryInterface(obj);
if (elem)
elem->GetInnerHTML(html);
// IE
CComBSTR html;
MSHTML::IHTMLElementPtr elem = obj;
if (elem)
elem->get_innerHTML(&html);
Your best bet seems to be to define your own interface and write different adapters. In the likeliness that your C++ code won't be employing all DOM traversing capabilities, your interface will only have to define a compact set of traversal functions.
As a bonus of defining your own interface, you can easily write a mock adapter for your unit testing.
I've never seen one. For my software, I simple wrote the extension in Firefox's javascript, and then created an Internet Explorer BHO (which I haven't finished yet).
Moonlight is released under LGPL, they may have something usable for you, if the licensing is ok.
Any reason why it has to be C++? Can't you use jQuery? Or something like http://webkit.org/blog/156/queryselector-and-queryselectorall/ in WebKit might do the trick..

GWT Unit Testing TDD and Tooling

I m just starting using gwt and so far so good, however after reading some sample code I wonder is it necesary to have a high level of test coverage? (I can see that most code is declarative and then add some attributes I can see the sense in checking so me particular attributes are there but not all)
Also i would be interested to know anything about what are the gotchas in TDDing with GWT
I m using eclipse so also if you are really happy with some particualrs add ins for GWT I would be happy to hear about that
Thanks for the input
edit: maybe I m asking a very wide question, but even little pieces of information will help
I come from having nvelocity views with jquery/extJs/prototype/scriptaculous and this is a bit different
When designing GWT applications to be easily testable, it's best to move as much logic out of the view as possible. Use a design pattern which makes GUI testing easier such as Model-View-Presenter (MVP), which is used widely in building desktop applications (The C#/.NET folks have written a lot about this pattern.)
You can use GWTTestCases to test remote communication and code that ultimately executes raw JavaScript (most of the GWT core classes require this, especially widgets). However, these tests are slow to execute, so you should prefer designs which put all that logic in objects that can be tested in plain ol' JUnit TestCases.
For more information about writing GWT applications test-first, I've written an article for Better Software magazine, which is available as a PDF online at my blog.
I think the best reference at the moment would be this Testing Methodologies Using Google Web Toolkit
I think you asked a pretty broad question, which is part of the reason why you didn't get a reply for a while.
Compared to traditional AJAX web development, one could argue a GWT application requires less testing. Because the GWT team has worked so hard to make sure that its widgets work consistently across all web browsers, you don't have to worry about cross-browser compatibility nearly as much for your own application.
That frees you up to focus on your own application. Create a separate test case for each of your own custom widgets and test that they behave as you expect, and then write higher-level tests for each module. Take the extra step to make your tests fully automatable - that way every time you make a change or are about to release, it's easy to run all of your tests.
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=DevGuideJUnitIntegration