• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 636

05 Dec 2025 03:27AM UTC coverage: 80.509%. Remained the same
636

push

github

hazendaz
Cleanup more old since tags

you guessed it, at this point going to jautodoc the rest so the warnings on builds go away ;)

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8249 of 10132 relevant lines covered (81.42%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.27
/src/main/java/com/meterware/httpunit/FrameHolder.java
1
/*
2
 * MIT License
3
 *
4
 * Copyright 2011-2025 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.httpunit;
21

22
import java.io.IOException;
23
import java.net.MalformedURLException;
24
import java.util.ArrayList;
25
import java.util.Enumeration;
26
import java.util.Hashtable;
27
import java.util.List;
28

29
import org.xml.sax.SAXException;
30

31
class FrameHolder {
32

33
    /** Map from a frame selector to its corresponding web response. **/
34
    private Hashtable _contents = new Hashtable<>();
1✔
35

36
    /** Map from a frame selector to its subframe selectors. **/
37
    private Hashtable _subframes = new Hashtable<>();
1✔
38

39
    /** The window which owns this frame holder. **/
40
    private WebWindow _window;
41

42
    /** The topmost frame in this frameholder. **/
43
    private FrameSelector _topFrame;
44

45
    FrameHolder(WebWindow window) {
1✔
46
        _window = window;
1✔
47
        _topFrame = FrameSelector.newTopFrame(window);
1✔
48
        DefaultWebResponse blankResponse = new DefaultWebResponse(window.getClient(), null, WebResponse.BLANK_HTML);
1✔
49
        _contents.put(_topFrame, blankResponse);
1✔
50
        HttpUnitOptions.getScriptingEngine().associate(blankResponse);
1✔
51
    }
1✔
52

53
    FrameSelector getTopFrame() {
54
        return _topFrame;
1✔
55
    }
56

57
    WebResponse getFrameContents(FrameSelector targetFrame) {
58
        if (targetFrame == FrameSelector.TOP_FRAME) {
1✔
59
            targetFrame = getTopFrame();
1✔
60
        }
61
        WebResponse response = get(targetFrame);
1✔
62
        if (response == null) {
1!
63
            throw new NoSuchFrameException(targetFrame.getName());
×
64
        }
65
        return response;
1✔
66
    }
67

68
    WebResponse getSubframeContents(FrameSelector frame, String subFrameName) {
69
        FrameSelector[] subframes = (FrameSelector[]) _subframes.get(frame);
1✔
70
        if (subframes == null) {
1✔
71
            throw new NoSuchFrameException(subFrameName);
1✔
72
        }
73

74
        for (FrameSelector subframe : subframes) {
1✔
75
            if (subframe.getName().equalsIgnoreCase(subFrameName)) {
1✔
76
                return get(subframe);
1✔
77
            }
78
        }
79
        throw new NoSuchFrameException(subFrameName);
1✔
80
    }
81

82
    WebResponse getParentFrameContents(FrameSelector frame) {
83
        return get(frame.getParent() == null ? _topFrame : frame.getParent());
1✔
84
    }
85

86
    WebResponse get(FrameSelector targetFrame) {
87
        return (WebResponse) _contents.get(targetFrame);
1✔
88
    }
89

90
    WebResponse get(String target) {
91
        FrameSelector frame = getFrame(_topFrame, target);
1✔
92
        return frame == null ? null : (WebResponse) _contents.get(frame);
1!
93
    }
94

95
    FrameSelector getFrame(String target) {
96
        return target.equals(_window.getName()) ? _topFrame : getFrame(_topFrame, target);
1✔
97
    }
98

99
    private FrameSelector getFrame(FrameSelector rootFrame, String target) {
100
        if (target.equalsIgnoreCase(WebRequest.TOP_FRAME)) {
1✔
101
            return _topFrame;
1✔
102
        }
103
        if (target.equalsIgnoreCase(rootFrame.getName())) {
1!
104
            return rootFrame;
×
105
        }
106

107
        return lookupFrame(rootFrame, target);
1✔
108
    }
109

110
    private FrameSelector lookupFrame(FrameSelector rootFrame, String target) {
111
        FrameSelector result = getFromSubframe(rootFrame, target);
1✔
112
        if (result != null) {
1✔
113
            return result;
1✔
114
        }
115
        if (rootFrame.getName().equals(target)) {
1!
116
            return rootFrame;
×
117
        }
118
        if (rootFrame.getParent() != null) {
1✔
119
            return lookupFrame(rootFrame.getParent(), target);
1✔
120
        }
121
        return null;
1✔
122
    }
123

124
    private FrameSelector getFromSubframe(FrameSelector rootFrame, String target) {
125
        FrameSelector[] subframes = (FrameSelector[]) _subframes.get(rootFrame);
1✔
126
        if (subframes == null) {
1✔
127
            return null;
1✔
128
        }
129

130
        for (FrameSelector subframe : subframes) {
1✔
131
            if (subframe.getName().equalsIgnoreCase(target)) {
1✔
132
                return subframe;
1✔
133
            }
134
        }
135
        for (FrameSelector subframe : subframes) {
1✔
136
            FrameSelector result = getFromSubframe(subframe, target);
1✔
137
            if (result != null) {
1✔
138
                return result;
1✔
139
            }
140
        }
141
        return null;
1✔
142
    }
143

144
    List<String> getActiveFrameNames() {
145
        List<String> result = new ArrayList<>();
1✔
146
        for (Enumeration e = _contents.keys(); e.hasMoreElements();) {
1✔
147
            result.add(((FrameSelector) e.nextElement()).getName());
1✔
148
        }
149

150
        return result;
1✔
151
    }
152

153
    /**
154
     * Determines the frame in which the reply to a request will be stored.
155
     */
156
    FrameSelector getTargetFrame(WebRequest request) {
157
        if (WebRequest.NEW_WINDOW.equalsIgnoreCase(request.getTarget())) {
1✔
158
            return FrameSelector.NEW_FRAME;
1✔
159
        }
160
        if (WebRequest.TOP_FRAME.equalsIgnoreCase(request.getTarget())) {
1✔
161
            return _topFrame;
1✔
162
        }
163
        if (WebRequest.SAME_FRAME.equalsIgnoreCase(request.getTarget())) {
1✔
164
            return request.getSourceFrame();
1✔
165
        }
166
        if (WebRequest.PARENT_FRAME.equalsIgnoreCase(request.getTarget())) {
1✔
167
            return request.getSourceFrame().getParent() == null ? _topFrame : request.getSourceFrame().getParent();
1✔
168
        }
169
        if (request.getSourceFrame().getName().equalsIgnoreCase(request.getTarget())) {
1✔
170
            return request.getSourceFrame();
1✔
171
        }
172
        FrameSelector targetFrame = getFrame(request.getSourceFrame(), request.getTarget());
1✔
173
        if (targetFrame == null) {
1✔
174
            targetFrame = _window.getClient().findFrame(request.getTarget());
1✔
175
        }
176
        return targetFrame != null ? targetFrame : FrameSelector.NEW_FRAME;
1✔
177
    }
178

179
    void updateFrames(WebResponse response, FrameSelector frame, RequestContext requestContext)
180
            throws MalformedURLException, IOException, SAXException {
181
        removeSubFrames(frame);
1✔
182
        _contents.put(frame, response);
1✔
183

184
        if (response.isHTML()) {
1✔
185
            HttpUnitOptions.getScriptingEngine().associate(response);
1✔
186
            requestContext.addNewResponse(response);
1✔
187
            WebRequest[] requests = response.getFrameRequests();
1✔
188
            if (requests.length > 0) {
1✔
189
                createSubFrames(frame, response.getFrameSelectors());
1✔
190
                for (WebRequest request : requests) {
1✔
191
                    if (request.getURLString().length() != 0) {
1✔
192
                        response.getWindow().getSubframeResponse(request, requestContext);
1✔
193
                    }
194
                }
195
            }
196
        }
197
    }
1✔
198

199
    private void removeSubFrames(FrameSelector frame) {
200
        FrameSelector[] subframes = (FrameSelector[]) _subframes.get(frame);
1✔
201
        if (subframes == null) {
1✔
202
            return;
1✔
203
        }
204

205
        _subframes.remove(frame);
1✔
206
        for (FrameSelector subframe : subframes) {
1✔
207
            removeSubFrames(subframe);
1✔
208
            _contents.remove(subframe);
1✔
209
        }
210
    }
1✔
211

212
    private void createSubFrames(FrameSelector frame, FrameSelector[] subframes) {
213
        _subframes.put(frame, subframes);
1✔
214
        for (FrameSelector subframe : subframes) {
1✔
215
            _contents.put(subframe, WebResponse.createBlankResponse());
1✔
216
        }
217
    }
1✔
218

219
    /**
220
     * Given the qualified name of a frame and the name of a nested frame, returns the qualified name of the nested
221
     * frame.
222
     */
223
    static FrameSelector newNestedFrame(FrameSelector parentFrame, final String relativeName) {
224
        if (relativeName == null || relativeName.isEmpty()) {
1!
225
            return new FrameSelector();
1✔
226
        }
227
        return new FrameSelector(relativeName, parentFrame);
1✔
228
    }
229

230
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc