Bug 63458

Summary: WebKitTestRunner needs layoutTestController.setPopupBlockingEnabled
Product: WebKit Reporter: Balazs Kelemen <kbalazs>
Component: Tools / TestsAssignee: Balazs Kelemen <kbalazs>
Status: RESOLVED FIXED    
Severity: Normal CC: aroben, hnandor, ossy, webkit.review.bot
Priority: P3 Keywords: LayoutTestFailure
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Implementation of setPopupBlockingEnabled method.
aroben: review-, aroben: commit-queue-
Implementation of setPopuBlockingEnabled method. none

Description Balazs Kelemen 2011-06-27 08:34:26 PDT
Sure he needs it.
Comment 1 Balazs Kelemen 2011-06-27 08:41:06 PDT
Same story as in https://bugs.webkit.org/show_bug.cgi?id=46714
(on Mac skipped by other reason but all wk2 platforms are affected).
Comment 2 Balazs Kelemen 2011-06-27 08:41:35 PDT
Created attachment 98733 [details]
Patch
Comment 3 Kenneth Rohde Christiansen 2011-06-27 09:27:12 PDT
Comment on attachment 98733 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=98733&action=review

> LayoutTests/ChangeLog:9
> +        Move the group to the section where the items have bug riport.

report
Comment 4 Balazs Kelemen 2011-06-27 10:16:57 PDT
Committed r89829: <http://trac.webkit.org/changeset/89829>
Comment 5 Nandor Huszka 2012-01-19 02:38:34 PST
Created attachment 123092 [details]
Implementation of setPopupBlockingEnabled method.

There are tests which fail the missing method so far, but now they fail because of an another problem. So I have rearranged the skiplist. These two tests:
- plugins/plugin-initiate-popup-window.html: now it fails on WK1, too
- fast/events/popup-blocked-from-fake-user-gesture.html: times out because of the lines in clickHandler1 function

    win = window.open("about:blank", "blank");
    shouldBeNonNull("win");

  win is null after opening.
Comment 6 Nandor Huszka 2012-01-20 00:33:27 PST
WebKit must be builded with the Tools/Scripts/build-webkit DEFINES+=ENABLE_CLIENT_BASED_GEOLOCATION=1 command, if we want to test this special function.
Comment 7 Balazs Kelemen 2012-01-24 07:07:49 PST
Looks good to me.
Comment 8 Adam Roben (:aroben) 2012-01-24 12:20:26 PST
Comment on attachment 123092 [details]
Implementation of setPopupBlockingEnabled method.

View in context: https://bugs.webkit.org/attachment.cgi?id=123092&action=review

Thanks for working on this!

> Source/WebCore/page/Settings.h:178
> +        void setPopupBlockingEnabled(bool);
> +        bool popupBlockingEnabled() const { return !m_javaScriptCanOpenWindowsAutomatically; }

It doesn't seem good to introduce these new accessors for the m_javaScriptCanOpenWindowsAutomatically member. We should just use the existing accessors instead of adding new ones.

> Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp:165
> +    for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)

I'm surprised you didn't have to specify const_iterator here.

We normally put the .end() iterator into a local rather than calling it on every iteration of the loop.
Comment 9 Nandor Huszka 2012-01-25 00:49:07 PST
(In reply to comment #8)

> It doesn't seem good to introduce these new accessors for the m_javaScriptCanOpenWindowsAutomatically member. We should just use the existing accessors instead of adding new ones.

You are right, we do not need the getter method, because it is not used in tests, but in my opinion the setter is necessary. I had a look at DRT and I found win and mac implementations. 
From LayoutTestControllerWin.cpp:
void LayoutTestController::setPopupBlockingEnabled(bool enabled) {
...
    preferences->setJavaScriptCanOpenWindowsAutomatically(!enabled);
}

From LayoutTestControllerMac.mm:
void LayoutTestController::setPopupBlockingEnabled(bool popupBlockingEnabled)
{
    [[[mainFrame webView] preferences] setJavaScriptCanOpenWindowsAutomatically:!popupBlockingEnabled];
}

This is the first reason why I implemented it in this way. The other reason is that tests use the layoutTestController.setPopupBlockingEnabled method. I think we rather do not need the setJavaScriptCanOpenWindowsAutomatically and javaScriptCanOpenWindowsAutomatically methods, these are unused in tests, however these are used in cpp files... It seems we need both accessors, or rewrite the tests to use the layoutTestController.setJavaScriptCanOpenWindowsAutomatically method.

> I'm surprised you didn't have to specify const_iterator here.
> 
> We normally put the .end() iterator into a local rather than calling it on every iteration of the loop.

I followed the implementation of similar methods in InjectedBundle.cpp. For example:
void InjectedBundle::setFrameFlatteningEnabled(WebPageGroupProxy* pageGroup, bool enabled)
{
    const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
    for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
        (*iter)->settings()->setFrameFlatteningEnabled(enabled);
}

I thought it would be correct if I write a similar method. However that is true .end() callings are unnecessary in every iteration, I will fix it, thank you for the comments.
Comment 10 Nandor Huszka 2012-01-25 00:56:15 PST
(In reply to comment #9)
> (In reply to comment #8)
> 
> > It doesn't seem good to introduce these new accessors for the m_javaScriptCanOpenWindowsAutomatically member. We should just use the existing accessors instead of adding new ones.

I have misinterpreted your comment. I understand already why we do not need the setPopupBlockingEnabled method in class Settings, I will fix it too.
Comment 11 Balazs Kelemen 2012-01-25 01:28:57 PST
> 
> > I'm surprised you didn't have to specify const_iterator here.
> > 
> > We normally put the .end() iterator into a local rather than calling it on every iteration of the loop.
> 
> I followed the implementation of similar methods in InjectedBundle.cpp. For example:
> void InjectedBundle::setFrameFlatteningEnabled(WebPageGroupProxy* pageGroup, bool enabled)
> {
>     const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages();
>     for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter)
>         (*iter)->settings()->setFrameFlatteningEnabled(enabled);
> }
> 
> I thought it would be correct if I write a similar method. However that is true .end() callings are unnecessary in every iteration, I will fix it, thank you for the comments.

I guess the drt code is using non-const iterators because constness of hashmap/hashset iterators was broken for a long time, i.e. you could not write myConstIt != myHashSet.end() because it did not compile. But it has been fixed not so far ago, so now you can use const iterators which is a better practice (if you don't modify the data of course).
Comment 12 Nandor Huszka 2012-01-25 02:01:21 PST
Created attachment 123900 [details]
Implementation of setPopuBlockingEnabled method.

Balazs, I see, thank you for the information.
Comment 13 Adam Roben (:aroben) 2012-01-25 08:52:56 PST
Comment on attachment 123900 [details]
Implementation of setPopuBlockingEnabled method.

Nice!
Comment 14 WebKit Review Bot 2012-01-25 09:21:49 PST
Comment on attachment 123900 [details]
Implementation of setPopuBlockingEnabled method.

Clearing flags on attachment: 123900

Committed r105884: <http://trac.webkit.org/changeset/105884>
Comment 15 WebKit Review Bot 2012-01-25 09:21:55 PST
All reviewed patches have been landed.  Closing bug.